Fade To Black..........
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.
You need to enable alpha blending.
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).
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).
Wouldn't you actually want glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)? That will let you fade to any color or texture.
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).
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.
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.
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...
(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...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement