Alpha blending with Textures

Started by
2 comments, last by Lord_Evil 15 years, 10 months ago
Hi! I'm trying to create a album list that rotates. I would like the most fron image of the album to be more transparent, so that you can see tha album item image behind more clearly. How an this be done? I create a list that I use. GLvoid BuildAlbumItem() { glColor4f(0.5f,0.5f,0.5f, 1.0f); AlbumItem = glGenLists(1); glNewList(AlbumItem,GL_COMPILE); glBegin(GL_QUADS); glNormal3f( 0.0f, 0.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glEnd(); glEndList(); } Then I use the list in my DrawGLScene function. At this moment I have only created two items in my album. Looks good but I need to add transparency. for( items = 0; items < 2; items++) { glLoadIdentity(); glTranslatef(1.4f + (2*items), 0.0f, -7.0f - (2 * items)); glCallList(AlbumItem); } Thanks!
Well I just want to join so I can get som help.
Advertisement
I'd say this thread should be moved to the OpenGL section, but I'll give you an answer anyway ;)

For transparency, you basically provide a vertex color that has an alpha component < 1. Just put it right before or after your glNormal3f() calls.

You also have to enable blending: glEnable(GL_BLEND);

Since the default texture mode is GL_MODULATE this should be all you have to do, except that you need to draw the quads from back to front (otherwise you would have no color information to blend with).

Look at the following example:

Let's define 2 quads facing the camera. Seen from above we'd have
111111111111     222222222222Now if you render quad 1 and then quad two you'd have the following effect:11111111111122222 //fragments contributing to the final image-----------------111111111111            22222The fragments of quad 2 that lie behind quad 1 are discarded.If you render quad 2 first you get:     2222222       //fragments above are blended with those below11111111111122222  //fragments contributing to the final image-----------------111111111111     222222222222
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
It worked fine.

Is it possible to self decide the alpha value?
If I want it to be 0.3f or 0.7f etc ?

Thanks
Well I just want to join so I can get som help.
If you have a fully opaque texture (no alpha or alpha = 1), then you can just set the alpha for the color.

You can play around with glBlendFunc() and glBlendEquation() to influence blending other than via alpha only.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!

This topic is closed to new replies.

Advertisement