Reputation: 3029
I have this code:
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
GLES20.glClearColor(0, 0, 0, 1.0f);
int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER,
getVertexShader());
int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER,
getFragmentShader());
mProgram = GLES20.glCreateProgram();
GLES20.glAttachShader(mProgram, vertexShader);
GLES20.glAttachShader(mProgram, fragmentShader);
GLES20.glLinkProgram(mProgram);
Matrix.setIdentityM(mMMatrix, 0);
**maPositionHandle = GLES20.glGetAttribLocation(mProgram, "aPosition");**
}
and after the marked line, maPositionHandle is -1 for some reason.
Here's my vert shader:
uniform mat4 uTMatrix;
uniform mat4 uMVPMatrix;
attribute vec4 aPosition;
attribute vec2 aTextureCoord;
varying vec2 vTextureCoord;
void main() {
gl_Position = uMVPMatrix * uTMatrix * gl_Position;
vTextureCoord = aTextureCoord;
}
as you can see, there is an attribute named aPosition, yet i get -1 and I get no drawing output on screen. How do I fix this? thanks.
Upvotes: 1
Views: 3567
Reputation: 7131
"aPosition" is not used in the shader code so the GLSL-compiler has optimized away the variable. Try using it in the gl_Position assignment and you will notice that it works.
gl_Position = uMVPMatrix * uTMatrix * aPosition;
Upvotes: 7