Alpha Blending problem

Started by
4 comments, last by deely 18 years, 8 months ago
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...
mov ax,4c00hint 21h
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.)
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.
mov ax,4c00hint 21h
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
typedef struct tagPIXELFORMATDESCRIPTOR { // pfd   //...  BYTE  cAlphaBits; 

I think that's the one. Try setting it to 8
Yeah, it was that.
Now it is running properly.
Thanks a lot!
mov ax,4c00hint 21h

This topic is closed to new replies.

Advertisement