Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top