Skip to main content
gamedev.net
🔒 Locked

Blending - Alpha buffer

Started by Kamos Feb 3, 2008 at 4:21 PM 3 replies 1.3k views
Original Post
Kamos
Kamos
Whenever I enable the alpha buffer the glColor4f overrides the color and alpha values from the texture. If I disable the alpha buffer all works fine. Unfortunately I need the alpha buffer. What am I missing? (See code below) Thanks in advance. Code: glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(0.0f,0.0f,-10.0f); glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA, GL_ZERO); glColor4f(1.0,1.0,1.0,1.0); glBindTexture(GL_TEXTURE_2D, ct.texID); glBegin(GL_QUADS); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f); glEnd(); And the Pixel format descriptor: static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be { sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 1, // Version Number PFD_DRAW_TO_WINDOW | // Format Must Support Window PFD_SUPPORT_OPENGL | // Format Must Support OpenGL PFD_DOUBLEBUFFER, // Must Support Double Buffering PFD_TYPE_RGBA, // Request An RGBA Format bits, // Select Our Color Depth 0, 0, 0, 0, 0, 0, // Color Bits Ignored 8, // Yes Alpha Buffer 0, // Shift Bit Ignored 0, // No Accumulation Buffer 0, 0, 0, 0, // Accumulation Bits Ignored 16, // 16Bit Z-Buffer (Depth Buffer) 0, // No Stencil Buffer 0, // No Auxiliary Buffer PFD_MAIN_PLANE, // Main Drawing Layer 0, // Reserved 0, 0, 0 // Layer Masks Ignored };
zedz
zedz
i believe 8, // Yes Alpha Buffer is for destination alpha, ie the window can store alpha values which u can use.
alpha in textures eg with GL_SRC_ALPHA doesnt need this info
what do u have the texture env set to? try GL_MODULATE
Kamos
Kamos
True. In this piece of code no alpha buffer is needed but I do need it somewhere else. But this piece of code does not place the texture on the screen it takes just place a white box of where the texture should be. It's like disabling GL_TEXTURE_2D, although here it is enabled. I don't understand why enabling the alpha buffer changes the outcome.

I have tried GL_MODULATE:

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

But the result is the same.

Just to be more clear, this is what I'm seeing and what I'm using for texture(TGA):
http://img150.imageshack.us/img150/5781/alphabufferproblemrw3.png
Kamos
Kamos
Problem remains unsolved...
I have found a different way to achieve my goal (without using the alpha buffer), but still I wonder why this doesn't work. I'd still like to know what's wrong.
Kamos
Kamos
Ok, this is kind of an old topic to bring back up, but I finally figured out what was wrong. It's kind of obvious.
Sometimes I play a game in windowed mode that requires 16 bit color quality on the desktop. So I kept it on 16 bit all the time because I don't see much difference between 32 and 16 bit (I have no fancy background on my desktop).
So what happened when trying to acquire the alpha buffer was that it wasn't there because I was running in 16 bit color quality.
I doubt other people will encounter the same problem, but if they do then the solution is to simply put color quality to 32 bit.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.