Multiple textures with GLSLShader (GLGraphics)
in
Contributed Library Questions
•
3 months ago
I'm not finding a way to access two sampler2d textures when using the GLSLShader object from GLGraphics, only the texture bound to unit 0 can be read.
First test was to add two textures to a model:
- model.initTextures(2);
- model.updateTexCoords(0, texCoords);
- model.setTexture(0, tex0);
- model.setTexture(1, tex1);
And define two sampler2d uniforms in my fragment shader:
- uniform sampler2D texture;
- uniform sampler2D normalMap;
But this way only the first defined sampler2d seems to receive a texture, the one bounded to unit 0.
Another method I tried was to bind the textures to the texture units:
- shader.start();
- shader.setTexUniform("texture", 0);
- gl.glActiveTexture(GL.GL_TEXTURE0);
- gl.glBindTexture(tex0.getTextureTarget(), tex0.getTextureID());
- shader.setTexUniform("normalMap", 1);
- gl.glActiveTexture(GL.GL_TEXTURE1);
- gl.glBindTexture(tex1.getTextureTarget(), tex1.getTextureID());
But the resullt is the same.
Using GLModelEffect this is rather easy, as in the xml file the uniform name and the texture unit are explicitly specified, but how can it be done with GLSLShader object?
Thanks!
1