prepare method

Future<bool> prepare()

Implementation

Future<bool> prepare() async {
  await Engine.instance.prepare();
  if (kDebugMode) {
    print('get instance');
  }

  String version = "300 es";

  var vs = """#version $version
precision highp float;
uniform vec4 camera;
in vec3 vPosition;
in vec2 vTex;
in vec4 vColor;
out vec4 vCol;
out vec2 TexCoord;

void main(void)
{
vec2 ofs = camera.zw;
  vec2 to = camera.xy;
  vec2 pos = vPosition.xy;
  pos = pos - to - ofs;
  pos.x = pos.x / ofs.x;
  pos.y = pos.y / ofs.y;

  gl_Position = vec4(pos.xy, vPosition.z, 1.0);
  TexCoord = vTex;
  vCol = vec4(vColor);
}
  """;

  var fs = """#version $version
precision highp float;
in vec2 TexCoord;
in vec4 vCol;
uniform sampler2D tTexture;
out vec4 color;

void main() {
vec4 c=texture(tTexture, TexCoord);
  color = vCol;
}
  """;

  Engine.instance.shader.creareProgram(0, vs, fs);
  Engine.instance.shader.useProgram(0);
  vs = """#version $version
precision highp float;
uniform vec4 camera;
in vec3 vPosition;
in vec2 vTex;
in vec4 vColor;
out vec4 vCol;
out vec2 TexCoord;

void main(void)
{
vec2 ofs = camera.zw;
  vec2 to = camera.xy;
  vec2 pos = vPosition.xy;
  pos = pos - to - ofs;
  pos.x = pos.x / ofs.x;
  pos.y = pos.y / ofs.y;

  gl_Position = vec4(pos.xy, vPosition.z, 1.0);
  TexCoord = vTex;
  vCol = vec4(vColor);
}
  """;

  fs = """#version $version
precision highp float;
in vec2 TexCoord;
in vec4 vCol;
uniform sampler2D tTexture;
out vec4 color;

void main() {
vec4 c=texture(tTexture, TexCoord);
  if (c.a<0.1) discard;

  color =vec4(c.b, c.g, c.r, c.a) * vCol;
}
  """;

  Engine.instance.shader.creareProgram(1, vs, fs);
  Engine.instance.shader.useProgram(1);
  // Write the positions of vertices to a vertex shader
  return true;
}