Small Blending Question
I am just trying to have a simple rectangle that has a alpha channel and blends it with the things around it. Like glass for example, you can see through it.
Here is the code:
glEnable(GL_ALPHA_TEST);
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//Ortho Screen
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0,800,0,600,-1,1);
//Draw the stuff
glColor4f(1, 1, 1, 0.5f);
glBegin(GL_QUADS);
glVertex3f(450, 100, 0);
glVertex3f(750, 100, 0);
glVertex3f(750, 500, 0);
glVertex3f(450, 500, 0);
glEnd();
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glDisable(GL_BLEND);
////////////////////////////
Those lines of code dont display anything. But when i change the blend function to something else, like GL_ONE, GL_ZERO for normal. it shows the rectangle but without blending. I thought that the blends i am using is what you would use for transparency.
Another question, why is it when ever i uncomment this line:
//glAlphaFunc(GL_GREATER,0.0f);
it doesnt display anything on the screen?
I thought that line of code is suppose to say, if alpha is greater than 0.0f, then it passes the test...
Please any help you can provide would be very nice.
Thanks
[edited by - UponTheEnd on February 24, 2004 12:39:36 AM]
"What we do in life, echos in eternity" -- Gladiator
You are in the wrong matrix mode when you draw the quad. Projection mode should only be used while you are setting up the projection matrix (perspective or orthographic). As soon as you have finished setting up the projection matrix you should switch back to the modelview matrix.
Enigma
Enigma
quote:
Original post by Enigma
You are in the wrong matrix mode when you draw the quad.
While the matrix mode may or may not be correct, its irrelevant. If it draws/displays with the different blending then its on screen.
OP:
Using ONE & ZERO effectivly disables blending, so we can be sure its actually on screen. A good start

Your comment about alpha testing is a good one - it should be testing exactly how you describe, and so have no effect. But you may somehow have alpha values of 0 for some reason, which would explain the behaviour. Have you still got a 0 alpha texture bound when you call this perchance? Try disabling texturing and see if that gets you the proper semi-transparent look.
[size="1"][[size="1"]TriangularPixels.com[size="1"]] [[size="1"]Rescue Squad[size="1"]] [[size="1"]Snowman Village[size="1"]] [[size="1"]Growth Spurt[size="1"]]
Thanks tons.
It was i had to disable 2d textures and it worked perfectly.
Can anyone tell me why it was doing what it was doing? (Not showing up at all) The texture bind was a valid one, and also i didnt do glTexCoord*(), so why would it have been a problem. Also i thought if there is a problem with a texture, it just shows some color in the box will the picture would be, not just disappear.
Can someone clear this up for me?
Thanks!
[edited by - UponTheEnd on February 25, 2004 7:37:36 PM]
It was i had to disable 2d textures and it worked perfectly.
Can anyone tell me why it was doing what it was doing? (Not showing up at all) The texture bind was a valid one, and also i didnt do glTexCoord*(), so why would it have been a problem. Also i thought if there is a problem with a texture, it just shows some color in the box will the picture would be, not just disappear.
Can someone clear this up for me?
Thanks!
[edited by - UponTheEnd on February 25, 2004 7:37:36 PM]
"What we do in life, echos in eternity" -- Gladiator
The problem is that OpenGL is a state machine. When you specify a texture coordinate it applies to every subsequent vertex until you change it. There is also an initial texture coordinate. So when you enable texturing, every vertex has a texture coordinate and every object is textured. If the texture coordinates for a polygon are all the same then the texture colour from that point in the texture will cover the entire polygon. Presumably the texel that was used was black, so you couldn''t see the object.
Enigma
Enigma
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement