Activating/using GL_TEXTURE1 at OpenGL ES 2.0 for Android

前端 未结 1 1678
無奈伤痛
無奈伤痛 2021-01-28 08:17

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.

相关标签:
1条回答
  • 2021-01-28 09:09

    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);
    
    0 讨论(0)
提交回复
热议问题