Jump to content
  • Advertisement
Sign in to follow this  
vivendi

glClearColor alpha

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

I'm trying to use glClearColor with a full alpha, but for some reason it isn't working.

What i'm doing is i only render to the back buffer. So i never call something like swapBuffers();
After that i'm reading all the pixels from the back buffer with glReadPixels(). All the RGB values are stored correctly, but the alpha value is always 255.

So every render i clear the screen and then i render a model. Shouldn't that leave me with a fully transparent screen except on the place where my model is drawn?

My code is basically like this:

void Render(void)
{
glClearColor(1.0f,0.0f,0.0f,0.0f);
glClear(GL_DEPTH_BUFFER_BIT);

drawModel();

glReadBuffer(GL_BACK); // probably not needed, but just in case
glReadPixels(0, 0, (GLsizei)width, (GLsizei)height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
}


But the backcolor is always red, why not transparent...?? Is there a setting that i'm missing??

Share this post


Link to post
Share on other sites
Advertisement

Try
glClearColor(0.0f,0.0f,0.0f,1.0f);

instead?


Ohh i thought transparency was set to 0.0f, but i tried it with 1.0f, still the same result though.

Np transparency :(

Any other ideas?

Share this post


Link to post
Share on other sites

The the alpha value is always coming out as fully opaque, then you don't have an alpha channel. Check the pixel format.


I can't really find anything usefull about that. I've been looking through alot of opengl APIs... Could you maybe point me in the right direction?

Share this post


Link to post
Share on other sites
It is not related to OpenGL, but to the windowing API you use. Where do you create the window and the rendering context? Somewhere you must say, or imply, what color format you want for your frame buffer. For example, in GLUT you need to specify the GLUT_ALPHA flag to the glutInitDisaplayMode function, and in the Windows API you need to set the cAlphaBits field of the PIXELFORMATDESCRIPTOR structure you pass to SetPixelFormat.

Share this post


Link to post
Share on other sites
glClear has a feature that it does not actually clear the color buffer unless the appropriate bits from the color buffer write mask are enabled via a call to glColorMask. (glColor states "The pixel ownership test, the scissor test, dithering, and the buffer writemasks affect the operation of glClear."). Perhaps you did not have the glColorMask for alpha channel writes enabled?

Share this post


Link to post
Share on other sites

glClear has a feature that it does not actually clear the color buffer unless the appropriate bits from the color buffer write mask are enabled via a call to glColorMask. (glColor states "The pixel ownership test, the scissor test, dithering, and the buffer writemasks affect the operation of glClear."). Perhaps you did not have the glColorMask for alpha channel writes enabled?

Well, it also has the "feature" that it doesn't clear the color buffer unless told to do so. Like, forgetting to specify the GL_COLOR_BUFFER_BIT... Didn't even notice that one in the original post. Good thing you brought up glClear, color buffers and bits, although in a different context.

Share this post


Link to post
Share on other sites

It is not related to OpenGL, but to the windowing API you use. Where do you create the window and the rendering context? Somewhere you must say, or imply, what color format you want for your frame buffer. For example, in GLUT you need to specify the GLUT_ALPHA flag to the glutInitDisaplayMode function, and in the Windows API you need to set the cAlphaBits field of the PIXELFORMATDESCRIPTOR structure you pass to SetPixelFormat.


Well the thing is, is that i'm not creating any window... I'm using the GLFW library which allows you to render stuff to the back buffer without creating a window (unlike the GLUT lib...). That was the whole reason i chose for GLFW.

I'm clearing my buffer now like this:

glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1.0f,0.0f,0.0f,0.5f);


Obviously, its not working. Guess i'll have to check if GLFW lets me set the pixel format somehowm since i have no real HANDLE to a window. Which is needed when setting the pixel format struct (if i understand it right..).

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!