Jump to content
  • Advertisement
Sign in to follow this  
deely

OpenGL Alpha Blending problem

This topic is 4893 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

Hello, I have a problem with alpha blending in OpenGL. I'm trying to do 2d hard shadows (described in tutorial on GameDev: "Dynamic 2d Soft Shadows"). Here is some piece of code:
glClear( ... );
glLoadIdentity();

glColor4f( 0.0f, 0.0f, 0.0f, 0.5f );
DrawBox( 100, 100, 100, 100 ); // just draw the square

glEnable( GL_BLEND );
glBelndFunc( GL_DST_ALPHA, GL_ONE );

glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
DrawBox( 0, 0, 800, 600 );

glDisable( GL_BLEND ); 
When I'am drawing a second square, its color should be multiplied by ALPHA value from the framebuffer (the first quad) This code is runnig properly on my video card (RADEON 9600), but when I'am trying to run this code on RIVA TNT or GeForce 2 MX, there's the only second square without any blending. It look's like alpha values of the first square are not written into the frame buffer... and I don't know where is the mistake...

Share this post


Link to post
Share on other sites
Advertisement
Make sure you've actually got destination alpha. If you don't explicitly ask for it, you may or may not get it. If you don't have it, DST_ALPHA will always be one, and hence you'll get no blending.
(So check the code where you create your window/OpenGL context.)

Share this post


Link to post
Share on other sites
Do you mean PFD_TYPE_RGBA flag in pixelformatdescriptor?
It's done. Here is my pixelformatdescriptor:


static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
0, 0, 0, 0, 0, 0,
0, 0,
0, 0, 0, 0,
0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};


I think it's correct.

Share this post


Link to post
Share on other sites
Mmm.. No, I don't think that's the one. I'm don't use Windows, so I can't say for sure, but I think there should be either a flag for destination alpha or a way to request a number of destination alpha bits. Check the documentation for the pixelformatdescriptor

Share this post


Link to post
Share on other sites
typedef struct tagPIXELFORMATDESCRIPTOR { // pfd   
//...
BYTE cAlphaBits;

I think that's the one. Try setting it to 8

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!