Hey hey,
I must have done something terribly wrong, hehe. I’m pretty new to openGL, so it’s all a matter of stumbling and getting up again, but here’s the del, bear with me. I’m writing a 2d game, using openGL to display the graphics. As a function of my graphicsengine, I wanted to draw a rect over the entire scene with any color and alpha value, so that I could dim the scene to black for example, or have an orange glow for levels in a vulcano.
Anyways, the fade to black works, simply using the following function I made:
////////////////////////////////////////////////////////////////////////////////
/// Draw a colored rectangle over the screen, with a specified alpha value.
///
/// \param Color The color of the overlay.
/// \param Alpha The alpha value the overlay should have.
/// \bug glColor4f seems to skip green, for some reason.
////////////////////////////////////////////////////////////////////////////////
void cEffectManager::DrawOverlay(sColor Color, GLfloat Alpha) {
// If it's 0, and therefore not visible, simply don't draw any overlay.
if(Alpha==0.0f) {
return;
} // if
glLoadIdentity();
glBegin(GL_QUADS);
glColor4f(Color.Red, Color.Green, Color.Blue, Alpha);
// glColor4f(1.0f, 1.0f, 1.0f, Alpha);
glVertex2f(0,
0);
glVertex2f(g_Graphics->GetWidth(),
0);
glVertex2f(g_Graphics->GetWidth(),
g_Graphics->GetHeight() );
glVertex2f(0,
g_Graphics->GetHeight() );
glEnd();
Fading to black works, as mentioned… but the fun (?) thing is, most other colors don’t. What happens is that the second parameter of glColor4f() is simply ignored completely. If I were to display a white square (the commented line in my function), it gives a pink overlay in my game… and (0,0,0) and (0,1,0) both display as black…
I have yet to isolate the cause of the bug, but I am at a loss here. Why on earth does openGL skip my green? I can’t seem to reproduce it on small scale…
Tony