Skip to content Skip to sidebar Skip to footer

Activating/using GL_TEXTURE1 At OpenGL ES 2.0 For Android

I'm trying to use the GL_TEXTURE1 texture unit to draw a simple shape. I know how to draw it using the standard GL_TEXTURE0, but when changing it something is not working. I though

Solution 1:

You need to specify active texture unit and assign a previously loaded texture to it.

For convenience, I've created a helper function which does all of this. It activates given texture unit, assigns texture with given ID to it and puts this value to sampler2D uniform of shader:

protected void setTexture2D(int textureUnit, int textureID, int uniformID) {
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + textureUnit);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureID);
    GLES20.glUniform1i(uniformID, textureUnit);
}

And then call it like this:

setTexture2D(0, textureID, uniformID);

Post a Comment for "Activating/using GL_TEXTURE1 At OpenGL ES 2.0 For Android"