Example #1
0
  protected boolean prepare(int fbufWidth, int fbufHeight) {
    if (ctx.useShader(this) && glIsProgram(program)) {
      glUseProgram(program);
      ctx.checkGLError("Shader.prepare useProgram");

      glUniform2f(uScreenSizeLoc, fbufWidth, fbufHeight);
      // ctx.checkGLError("Shader.prepare uScreenSizeLoc set to " + fbufWidth + " " + fbufHeight);

      glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBuffer);
      ctx.checkGLError("Shader.prepare BindBuffer");

      glEnableVertexAttribArray(aMatrix);
      glEnableVertexAttribArray(aTranslation);
      glEnableVertexAttribArray(aPosition);
      if (aTexture != -1) glEnableVertexAttribArray(aTexture);
      ctx.checkGLError("Shader.prepare AttribArrays enabled");

      glVertexAttribPointer(aMatrix, 4, GL_FLOAT, false, VERTEX_STRIDE, 0);
      glVertexAttribPointer(aTranslation, 2, GL_FLOAT, false, VERTEX_STRIDE, 16);
      glVertexAttribPointer(aPosition, 2, GL_FLOAT, false, VERTEX_STRIDE, 24);
      if (aTexture != -1) glVertexAttribPointer(aTexture, 2, GL_FLOAT, false, VERTEX_STRIDE, 32);
      ctx.checkGLError("Shader.prepare AttribPointer");
      return true;
    }
    return false;
  }