Jump to content
  • Advertisement
Sign in to follow this  
F-Kop

OpenGL Fade To Black..........

This topic is 3974 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 using OpenGL and SDL. I'm trying to draw a transparent black rectangle over the screen to make it fade to black, but it refuses to appear transparent. It's just all black. Here's the color function I used: glColor4ub( 0, 0, 0, factor ); Factor goes from 0 to 255 and nothing happens. I also tried just 0 and 1, and it didn't work. It didn't work when i tried glColor4f from 0.0 to 0.1 either. Am I doing something wrong? Any help is appreciated.

Share this post


Link to post
Share on other sites
Advertisement
You need to enable alpha blending.


glBlendFunc( GL_SRC_ALPHA, GL_ONE );
glEnable( GL_BLEND );



You may also need to turn depth testing off (and in that case, make sure the quad is the last thing drawn). But other than that, you have the right idea (fading from 0 to 255).

Share this post


Link to post
Share on other sites
Wouldn't you actually want glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)? That will let you fade to any color or texture.

Share this post


Link to post
Share on other sites
I've been checking out some OpenGL reference pages and they don't give much of an explanation. If it makes a difference, I'm using glOrtho to render in 2D, and everything has the same depth (0.0f).

Share this post


Link to post
Share on other sites
glEnable( GL_ALPHA_TEST );
glAlphaFunc( GL_GREATER, 1.0 );

glEnable( GL_BLEND );
glBlendFunc( GL_ONE, GL_ONE );

Blending is enabled, but I have no idea which alpha function to use.

Share this post


Link to post
Share on other sites
Use glBlendFunc( GL_SOURCE_ALPHA, GL_ONE_MINUS_SOURCE_ALPHA );
(the exact syntax is available in the ogl reference, but something along those lines)
This means that for the rectangle, you use the alpha specified by glColor, and for what is already on screen, you use one minus that. That means the final color is computed to be rectangle_color * x + existing_color * (1-x). Over time, let x go from 0 to 1, and the effect is complete...

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!