Jump to content
  • Advertisement
Sign in to follow this  
Hachaso

Alpha blending with Textures

This topic is 3709 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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

222222222222

Now if you render quad 1 and then quad two you'd have the following effect:

11111111111122222 //fragments contributing to the final image
-----------------

111111111111

22222

The 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 below
11111111111122222 //fragments contributing to the final image
-----------------

111111111111

222222222222



Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!