View Full Version : glEnable(GL_TEXTURE_2D) conflicts with primitives blending?
12-03-2006, 03:25 PM
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:
glClearColor( 0.0f, 0.0f, 1.0f, 0.0f );
}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.
12-03-2006, 03:40 PM
Why do you have depth testing off? turn it on
12-03-2006, 04:31 PM
It sounds like you need to order your primitives from front to back. (order in which you render them)
I don't remember if it closer first farthest last or the other way around but I'm sure someone can fill me in. (or try it both ways)
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.
12-03-2006, 06:38 PM
I just want to draw a simple red square by using four glVertex3f().
I can't even draw the square and the textures if I turn the depth test on.
I try to draw the square first in Render(), but it doesn't show up.
12-03-2006, 07:35 PM
Ok, 1st is your winding order correct? If not change it or change glFrontFace().
2nd which are you using? glOrtho or gluPerspective? Make sure your near/far planes are correct.
3rd what/how are you setting up to draw this one quad?
If all is setup correctly you shouldn't have to turn off depth testing to see it.
you should disable texture to draw simple red quad. You sad? when you turn off texture the quad is drawing. This the right way.
12-04-2006, 12:27 AM
des allready answered your question:
if the coords are not correct the square can have the alpha 0 everywhere. That's because it not rendering.And then you wrote:
I just want to draw a simple red square by using four glVertex3f().Then why do you enable GL_TEXTURE_2D?
Draw a quad:
glEnd();Draw a textured quad:
glEnd();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.
12-04-2006, 02:34 PM
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 :
// And now, I do not use textures anymore, then
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.