• ### Announcements

#### Archived

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

# 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 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 on other sites
i used GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA and it ended up not blended at all.

##### Share on other sites
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 on other sites
Isnt glColor4f being ignored due the fact there is a texture binded to the quad?

##### 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 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 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 on other sites
okay, turning off the lighting workd wonderfully, now is there a way to get the same result with lighting enabled?

##### 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 on other sites
that''s what i was doing, but it didn''t really seem like the "right" way to do things.

##### 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

• ### Forum Statistics

• Total Topics
627694
• Total Posts
2978673
• ### Similar Content

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• By Defend
I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
* make lots of VAO/VBO pairs and flip through them to render different objects, or
* make one big VBO and jump around its memory to render different objects.
I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?

• 19
• 14
• 12
• 10
• 12