Skip to main content
GameDev.net gamedev.net
🔒 Locked

quad alpha blending

Started by thedirt Aug 9, 2007 at 5:54 PM 2 replies 700+ views
Original Post
thedirt
thedirt
I thought this should render a half opaque quad in the middle of the screen. But it is solid. What am I missing? glEnable( GL_ALPHA_TEST ); glBegin( GL_QUADS ); glColor4f( 1.0f, 0.0f, 0.0f, 0.5f ); glVertex3f( -2.0f, 2.0f, 0.0f ); glVertex3f( 2.0f, 2.0f, 0.0f ); glVertex3f( 2.0f, -2.0f, 0.0f ); glVertex3f( -2.0f, -2.0f, 0.0f ); glEnd(); Thanks,
julienr
julienr
You should have a look at :
http://www.opengl.org/resources/faq/technical/transparency.htm

Especially 15.020 How can I achieve a transparent effect?"
rpreller
rpreller
GL_ALPHA_TEST is used to throw away fragments depending on how the alpha value is related to a comparison value. The following will cause any fragments with an alpha of greater than 0.5 to not be drawn.

glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.5f);

GL_BLEND is used to do actual blending. It is very flexible, with the params being passed to glBlendFunc determing the equation used to calculate the final pixel color based on the current pixel color multiplied by one of the parameters plus the pixel color of the object being drawn multiplied by its own parameter.

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

http://pyopengl.sourceforge.net/documentation/manual/glBlendFunc.3G.html
thedirt
thedirt
Cool, thanks guys -- it works.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.