I have a program rendering transparent .tga files with no problem. But it fails when I try to make it render additional transparent squares. Here’s the original working code structure:
If I add a function rendering a square in Render() behind RenderTGA(), it won’t work. The function just has glBegin(), four lines of glVertex3f(), and glEnd(). But If I wrap the function with glDisable(GL_TEXTURE_2D) and glEnable(GL_TEXTURE_2D), the square is drawn.
I don’t understand why, and the current solution might not be the best solution. Please help me! thanks.
I did not realy understand what square do you need to reder? is it textured square? If yes? than you should assign texture coords too, else the square will be not correct.
And here is some thing - when you don’t assign texture coords OpenGL do it. Your texture have alpha values, so if the coords are not correct the square can have the alpha 0 everywhere. That’s because it not rendering.
If you don’t use glTexCoord then all your vertices will be at the same point on texture, and therefore you will render just one texel of texture. If it happen to have alpha value = 0 then you won’t see it.
I tried to draw both textures and primitive squares in the same time in my program. The textures have no problem (of course with GL_TEXTURE_2D enabled). But the square is not drawn until I disable GL_TEXTURE_2D (but the textures will have problems now). I am confused why both of them can no exist in the same time, and I believe what des said is the answer.
if the coords are not correct the square can have the alpha 0 everywhere. That’s because it not rendering.
With GL_TEXTURE_2D enabled, OpenGL expects coords for each vertex, but there is none for the square.
So I have to disable GL_TEXTURE_2D before drawing the squares, and enable it back before drawing textures.
I’m not sure, but perhaps you misunderstood the texture management.
When you draw your quad, OpenGL need to know if it must use the texture to fill your quad, or not. There is no conflict : it is yes or it is no. But it changes from a quad to another one, inside the draw pass.
glDisable/glEnable GL_TEXTURE_2D is used for this : just to say to OpenGL “You will need the texture for this quad”.
This is not only for initialisation: you can use it in live. To be true, you must use it in live in fact, like this:
// For my textured quad :
glEnable (GL_TEXTURE_2D);
renderTexturedQuad ();
// And now, I do not use textures anymore, then
glDisable (GL_TEXTURE_2D);
renderColoredQuad ();