0
votes

I'm trying to darken my display by drawing a fullscreen black quad, but with only 0.5 alpha. the first frame I render, this works correctly, however after the first frame I only get a black screen.

There's a lot of rendering going on, but here's all the pertinent openGL calls (I think):

initializing openGL (once)

glClearColor(0, 0, 0, 1);
glDisable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

render a frame

glClear(GL_COLOR_BUFFER_BIT);

//render things normally (some colored rectangles)

glColor4f(0,0,0,.5);
//draw fullscreen quad
//flip buffers

I'm really unsure of what could possibly be going wrong here. Moreover, if I use a color besides black, it produces an image tinted to that color, which (I presume), is what should happen. I've gone through my understanding of the math, and I can't figure out how black would come out, or why it would be different from frame to frame, so I assume I must be missing some other aspect of openGL that would cause the change?

1
just a guess, but is it possible your glColor4f ends up affecting the other drawing? You're not showwing how you draw what you want to darken, but if it only works first frame, it's likely a side-effect of your code to darken affecting the early part of the frame. so glColor4f is a likely culpritBahbar
Ah! the alpha from the glColor4f carries over! Damnit, I was being an idiot. Thanks!zacaj

1 Answers

1
votes

Well, if that was the case, let me write it as a full answer then.

If it only works first frame, it's likely a side-effect of your code to darken affecting the early part of the frame. so glColor4f is a likely culprit. So consider the possibility that your glColor4f ends up affecting the other drawing.