OpenGL transparency question?
I want an image to fade away on the screen. The game uses OpenGL. I've been looking around for some sort of transparency function but I can't seem to find it. 
Thanks!

Thanks!
If you want the whole viewport to fade to black (or something) you can just draw a rectangle on top of it. Assuming that what you mean is a textured polygon in a part of a scene, you could use GL_MODULATE for glTexEnv and ramp the alpha value in your glColor.
backslash Wrote:If you want the whole viewport to fade to black (or something) you can just draw a rectangle on top of it. Assuming that what you mean is a textured polygon in a part of a scene, you could use GL_MODULATE for glTexEnv and ramp the alpha value in your glColor.
Thanks for the quick replay.
What I'm trying to do is the latter of the 2. Sorry I'm new to this OpenGL stuff, could you write an example in code?Thank you!
DoG Wrote:You're probably looking for "blending".
My game is just a simple 2d game. (if that helps) All I want is a small image to fade away on the screen.
Thanks!
Right, as DoG said, you need blending. glEnable(GL_BLEND). You can set your translucency different ways, but glColor4f(r, g, b, alpha) is probably what you'll start with -- "alpha" being your opacity/translucency, and r, g, and b all being 1.0f if you just want a straight fade. Then it also depends on your blend function, but that's another story we'll talk about once you get blending and glColor4f doing something, but not the way you want.
AnotherJake Wrote:Right, as DoG said, you need blending. glEnable(GL_BLEND). You can set your translucency different ways, but glColor4f(r, g, b, alpha) is probably what you'll start with -- "alpha" being your opacity/translucency, and r, g, and b all being 1.0f if you just want a straight fade. Then it also depends on your blend function, but that's another story we'll talk about once you get blending and glColor4f doing something, but not the way you want.
Thanks, but I still can't seem to figure this out.
So I tried to go back to just triangles but it still doesn't work.
What's wrong with this code:Code:
glEnable(GL_BLEND);
glColor4f(1.0f,1.0f,1.0f,0.5f);
glBegin(GL_TRIANGLES);
glVertex3f( 0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glEnd();
Thanks!
What's your blend function? Try calling
before you draw the triangle.
Code:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Thank you!
Ok, so I've gotten it to work on the triangles but now when I try to put it in my game it will only affect the image that was drawn first (the background) but I want it to affect the last image drawn.
Thanks!
Ok, so I've gotten it to work on the triangles but now when I try to put it in my game it will only affect the image that was drawn first (the background) but I want it to affect the last image drawn.Thanks!
in openGL, you can have a couple different color functions, the ones you probably want are
glColor4f() or glColor4d()
they specify the r,g,b,a with a float or double respectively. What you want is the 'a' or alpha, this specifies the transparency of the object you are coloring. The alpha value ranges from 0 to 1, with 1 being opaque and 0 being completely transparent. So if you want to have something fade away, you will have away over time to change that alpha value.
glColor4f() or glColor4d()
they specify the r,g,b,a with a float or double respectively. What you want is the 'a' or alpha, this specifies the transparency of the object you are coloring. The alpha value ranges from 0 to 1, with 1 being opaque and 0 being completely transparent. So if you want to have something fade away, you will have away over time to change that alpha value.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| OpenGL transparency | green_ghost | 4 | 3,678 |
Sep 6, 2008 10:52 AM Last Post: green_ghost |
|

