’m observing a strange behavior from my application which I hope you can explain to me.
You see, I have these two 3D textures that are being sent to the fragment shader and are rendered perfectly OK. But there is a problem, As soon as I even create another texture (it’s a 1D texture), a black screen is being rendered instead of the correct former result.
About this 1D texture, I’m not even sending it to the fragment shader. The minute I call glTexImage1D(…) the black screen shows up. I comment this line and it goes away!!And the two textures are rendered.
I figured there has to be some kind of problem with texture units. Because when I run the application with gDebugger, the texture unit of one of 3D textures is THE SAME as the one assigned to the 1D texture.
I did not assign any texture unit to the 1D texture, I just created it. Apparently texture unit GL_TEXTURE0 is being automatically assigned to the 1D texture. The weird part is that although I use GL_TEXTURE2 and GL_TEXTURE3 for the 3D texture, one of them is being bound to GL_TEXTURE0 as a result of calling glTexImage1D!
Here is a snapshot from the textures list window of gDebugger:
Texture 1 (unit 2 ,bound3d)-enabled
Texture 2 (unit 0 ,bound1d)
Texture 3 (unit 0 ,bound3d)-Enabled (unit 3,bound3D)-enabled
Why is this happening?
the problem is not why texture 1D is being bound to GL_TEXTURE0, it is why it can affect the state of another already bound texture. the code is like this :
.
...
// generating the first texture_3d
glTexImage(GL_TEXTURE_3D,....);
glBindTexture(GL_TEXTURE_3D,id1);
//render loop for the first texture_3d
GLuint glEnum = GL_TEXTURE2;
vtkgl::ActiveTexture(glEnum);
glBindTexture(vtkgl::TEXTURE_3D,id1);
program->setUniform("TEX1",2);
// generating the second texture_3d
glTexImage(GL_TEXTURE_3D,....);
glBindTexture(GL_TEXTURE_3D,id2);
//render loop for the first texture_3d
GLuint glEnum = GL_TEXTURE3;
vtkgl::ActiveTexture(glEnum);
glBindTexture(vtkgl::TEXTURE_3D,id2);
program->setUniform("TEX2",3);
// generating texture 1D
glTexImage(GL_TEXTURE_1D,....);
glBindTexture(GL_TEXTURE_1D,id3);
we expect GL_TEXTURE2 and GL_TEXTURE3 to be active but gDebugger indicates that GL_TEXTURE0 and GL_TEXTURE2 are active.
You should not have both 1D and 3D textures bound to the same texture unit at the same time. To avoid this, either unbind the 3D texture:
glBindTexture()or switch to a new texture unit:vtkgl::ActiveTexture()before binding the 1D texture.As the above poster has stated, the call to
vtkgl::ActiveTexture()must come before the corresponding call toglBindTexture().