Do you have to adjust the pixel format to allow for blending?

Started by
4 comments, last by PnP Bios 19 years, 5 months ago
I was just wondering. I have this at the top: glEnable(GL_BLEND); glBlendFunc(GL_ALPHA, GL_ONE); glDisable(GL_DEPTH_TEST); This is a chunk of my pfd setup: pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 24; pfd.cDepthBits = 16; pfd.cAlphaBits = 16; pfd.iLayerType = PFD_MAIN_PLANE; and here is my render function. void Render(void) { // OpenGL animation code goes here static float theta = 0.0f; glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); glClear( GL_COLOR_BUFFER_BIT ); glPushMatrix(); glRotatef( theta, 0.0f, 0.0f, 1.0f ); glBegin( GL_TRIANGLES ); glColor4f( 1.0f, 0.0f, 0.0f,1.0 ); glVertex2f( 0.0f, 4.0f ); glColor4f( 0.0f, 1.0f, 0.0f,1.0 ); glVertex2f( 0.87f*4, -0.5f*4 ); glColor4f( 0.0f, 0.0f, 1.0f,1.0 ); glVertex2f( -0.87f*4, -.5f*4 ); glEnd(); glPushMatrix(); glRotatef( theta, 0.0f, 0.0f, 1.0f ); glBegin(GL_QUADS); glColor4f(1,1,1,0); glVertex2f(-2,2); glVertex2f(2,2); glVertex2f(2,-2); glVertex2f(-2,-2); glEnd(); glPopMatrix(); glPopMatrix(); theta += 1.0f; } Whats weird is that the quad shows up fully opaque. I'm stumped. I think that I might not be setting the the PFD right.
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
Advertisement
Try 32 instead of 24 - I believe ALPHA is lumped in with the color bits. 24 bits imply no alpha.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
That should only matter if you need the colour buffer to have alpha, which you don't in this case. Is your glEnable(GL_BLEND); etc. called before or after you create your OpenGL context? It should be after.

Enigma
GL_ALPHA is not a valid blend function factor. Check the documentation on glBlendFunc for a list of valid factors.

And the cColorBit in the pixel format descriptor is the number of color bits in the framebuffer, excluding alpha. But you don't need a destination alpha if you're only doing source alpha blending.
Good call. I missed that. You probably want GL_SRC_ALPHA.

Enigma
I'll try some of this tomorow at school. Thanks guys. Man, it's been a while since i've done ogl. Never got this far before either.
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One

This topic is closed to new replies.

Advertisement