I have an OpenGl application on an operating system that can snatch the OpenGL context away when the application loses focus, even though the application remains in memory. This results in a screen flicker as I re-load textures into the new OpenGL context when the application returns to focus.
I am working on breaking up the re-loading into increments so it looks better. But I am also wondering about this possibility:
- When the program gets notice that it will lose focus, capture the “average” color of the display (or the primary texture).
- When the program regains focus, do a very quick glClearColor(r,g,b) with the color captured in step 1.
- Then, re-load the textures normally while the user sees the color set in step 2.
I am thinking this would be sort of a visual trick to make the flicker less noticeable. There’s a catch: I am thinking that capturing an aggregate color by averaging every pixel would take too long and not be worth it.
So I am wondering if there is any OpenGl trick that would let an application get a rough estimate of the average color that a user sees on the screen?
The fastest way I’ve heard of to average a screen’s color is to copy it to a texture, call
glGenerateMipmap, and grab the smallest layer (1×1 mip level), which will contain an average of the colors of the pixel. That doesn’t sound particularly fast to me though, so not sure if it will be helpful for your purposes.