Hi!
I’m just trying to get two (or more) textures from jogl into my glsl fragment shader.
jogle global for TMU IDs:
//-----global-------//
int[] tmu = new int[2];
//shader program handle
int p_texture;
jogle setup textures in init method:
//----- init -------//
//---SETUP TEXTURES
//---base texture
gl.glGenTextures(2, tmu, 0);
gl.glClientActiveTexture(GL.GL_TEXTURE0);
gl.glEnable(GL.GL_TEXTURE_2D);
gl.glBindTexture(GL.GL_TEXTURE_2D, tmu[0]);
textureTBase = null;
try {
// TextureReader utility to read in Textures
textureTBase = TextureReader.readTexture("data/Fieldstone.jpg");
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
//set teximage
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, textureTBase.getWidth(), textureTBase.getHeight(), 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, textureTBase.getPixels());
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER,GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER,GL.GL_LINEAR);
//---bump texture
gl.glClientActiveTexture(GL.GL_TEXTURE1);
gl.glEnable(GL.GL_TEXTURE_2D);
gl.glBindTexture(GL.GL_TEXTURE_2D, tmu[1]);
textureTBump = null;
try {
// TextureReader utility to read in Textures
textureTBump = TextureReader.readTexture("data/FieldstoneBump.jpg");
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, textureTBump.getWidth(), textureTBump.getHeight(), 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, textureTBump.getPixels());
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER,GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER,GL.GL_LINEAR);
jogle setting up cube with texture coords and calling shader:
gl.glEnable(GL.GL_TEXTURE_2D);
gl.glClientActiveTexture(GL.GL_TEXTURE0);
gl.glBindTexture(GL.GL_TEXTURE_2D, tmu[0]);
gl.glUniform1iARB(gl.glGetUniformLocationARB(p_texture, "tex"),0);
gl.glClientActiveTexture(GL.GL_TEXTURE1);
gl.glBindTexture(GL.GL_TEXTURE_2D, tmu[1]);
gl.glUniform1iARB(gl.glGetUniformLocationARB(p_texture, "tex2"),1);
gl.glUseProgramObjectARB(p_texture);
gl.glColor3f(1.0f, 1.0f, 1.0f);
// Ausgabe Seite vorne (=1)
gl.glBegin(GL.GL_QUADS);
gl.glNormal3f(0.0f, 0.0f, 1.0f);
gl.glTexCoord2f(0.0f, 0.5f); gl.glVertex3f(-0.5f, 0.0f, 0.5f);
gl.glTexCoord2f(0.333333f, 0.5f); gl.glVertex3f(0.5f, 0.0f, 0.5f);
gl.glTexCoord2f(0.333333f, 1.0f); gl.glVertex3f(0.5f, 1.0f, 0.5f);...
.....
I think the code of the fragmentshader is unimportant. I’ve implemented some functions to check if both textures are loaded.
Problem:
I get only one Texture into the fragment shader!!
Facts:
The program just takes the texture that was bound the latest time!
Uniform doesn’t have any effect.
Both textures are saved to GL_TEXTURE0. (tmu[0] and tmu[1])
Could anybody help me please?
thx pat