Hi,
I wnat to load 2 textures and use them both in the fragment shader.
I first load the textures:
glBindTexture(GL_TEXTURE_2D, tex0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, 512, 512, 0, GL_RGBA, GL_FLOAT, data1);
glBindTexture(GL_TEXTURE_2D, tex1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, 512, 512, 0, GL_RGBA, GL_FLOAT, data2);
then I load my shader programs, and set the texturelocations:
texLoc0 = glGetUniformLocationARB(spTEST.progobj, "texUnit0");
glUniform1iARB(texLoc0, 0);
texLoc1 = glGetUniformLocationARB(spTEST.progobj, "texUnit1");
glUniform1iARB(texLoc1, 1);
The I draw a simple quad to show the texture:
glUseProgramObjectARB(program);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_3D, tex0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_3D, tex[1]);
glBegin(GL_QUADS);
{
glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f);
glTexCoord2f(1, 0); glVertex3f( 1, -1, -0.5f);
glTexCoord2f(1, 1); glVertex3f( 1, 1, -0.5f);
glTexCoord2f(0, 1); glVertex3f(-1, 1, -0.5f);
}
glEnd();
glUseProgramObjectARB(0);
my fragment shader code:
varying vec2 texCoord;
uniform sampler2D texUnit0;
uniform sampler2D texUnit1;
vec4 voxel;
vec4 voxel2;
void main()
{
voxel = texture2D(texUnit0, texCoord);
voxel2 = texture2D(texUnit1, texCoord);
gl_FragColor = voxel;
}
voxel1 and voxel2 give me both the color from the second texture!
It seems the first texture gets overwritten by the second! There is no way to get the first texture data visible, only the second…what do I forget? Do I have to change the order of some commands? please help.