Archived

This topic is now archived and is closed to further replies.

Mike

OpenGL Alpha blending with opengl

Recommended Posts

I''m just trying to draw a quad that is semi-transparent over what has already been drawn. I call glBlendFunc( GL_SRC_ALPHA, GL_ONE ); in my gl init code and when i go to draw the quad that i want to blend with what''s on the screen i call glEnable( GL_BLEND ) and after i''m done drawing that quad i call glDisable( GL_BLEND ). This kind of works. The quad blends with what''s there but very poorly. I expected to be able to control the alpha blending with the fourth parameter in glColor4f() which I call like so:
	glBindTexture( GL_TEXTURE_2D, m_texture[1] );

	if( m_bBlend )
	{
		glEnable( GL_BLEND );
		glDisable( GL_DEPTH_TEST );
	}

	glBegin( (m_bWireFrame)? GL_LINE_LOOP : GL_QUADS  );
		glNormal3f( 0.0f, 0.0f, 1.0f );
		glColor4f( 1.0f, 1.0f, 1.0f, 0.5f );
		glTexCoord2f( 0, 0 ); glVertex3f( -60, -10,  -95);
		glTexCoord2f( 10, 0 ); glVertex3f(  60, -10,  -95);
		glTexCoord2f( 10, 1 ); glVertex3f(  60,  10,  -95);
		glTexCoord2f( 0, 1 ); glVertex3f( -60,  10,  -95);
	glEnd();

	if( m_bBlend ) 
	{ 
		glEnable( GL_DEPTH_TEST ); 
		glDisable( GL_BLEND );
	}
 
What is wrong with what i have done?

Share this post


Link to post
Share on other sites
try GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA. Also, make sure the transparent polygon is drawn AFTER everything else. If you have multiple transparent polygons, you have to sort them and draw them furthest to closest.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
An alternative to drawing the transparent polygon last is surrounding the drawing of transparent polygons with a disable/enable of depth WRITING (make sure GL_DEPTH_TEST is still enabled though). Disabling is done via glDepthMask(GL_FALSE), and enabling with GL_TRUE.

Share this post


Link to post
Share on other sites
no it isn t as far as i know you can set specific alpha values for each vertex that way

would be interesting if you could do lighning that way as well
black color for the shadows vertices and white colors for the enlightened*spelling?* vertices

Share this post


Link to post
Share on other sites
u have normal + color!
with lioghting enabled color is ignored (unless u use color_material) so first disable lighting + then try it

http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html

Share this post


Link to post
Share on other sites
zedzeek is right. With lighting enabled, the alpha component is taken to be that of the diffuse material color, and glColor is ignored. The material color can be set by using glMaterial, or made to track the current color by using glColorMaterial.

http://users.ox.ac.uk/~univ1234

Share this post


Link to post
Share on other sites
okay, turning off the lighting workd wonderfully, now is there a way to get the same result with lighting enabled?

Share this post


Link to post
Share on other sites
yes there is BUT u dont want to do it i beieve
use color_material
why dont u want to do it?
cause youre draw one quad over the screen ie 4 vertices
what u shoudl do is turnoff lighting draw quad + then turn lighting back on.

http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html

Share this post


Link to post
Share on other sites
i assure u it is the right way to do things

http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html

Share this post


Link to post
Share on other sites