saarraz1
saarraz1

Reputation: 3029

OPEN GL ES 2.0 - glGetAttribLocation returning -1

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

Answers (1)

Ville Krumlinde
Ville Krumlinde

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

Related Questions