Alpha blending with Textures
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!
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
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
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
Is it possible to self decide the alpha value?
If I want it to be 0.3f or 0.7f etc ?
Thanks
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.
You can play around with glBlendFunc() and glBlendEquation() to influence blending other than via alpha only.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement