I require to fade out the entire screen(a gtk window that occupies the entire screen) to black/some color and fade in the content for the window back again.
Opengl does this by alpha texture blending I believe but really don’t understand the procedure in detail regarding swapping buffers etc.
Can anybody please provide me with workable sample code so that I could be able to pick it up from there?
Then you are doing it wrong.
Are you really sure you enabled blending ? And drawing the black quad last ? With alpha going from 1 to 0 ?
Show your code.
for (;
{
//Draw Quad that fits the screen
//(found the coords with try-and-error principle;))
glBegin(GL_QUADS);
glColor4f(0.0f,0.0f,0.0f,alpha);
glVertex3f(1.15f,1.15f,-2.0f);
glVertex3f(-1.15f,1.15f,-2.0f);
glVertex3f(-1.15f,-1.15f,-2.0f);
glVertex3f(1.15f,-1.15f,-2.0f);
glEnd();
glFlush();
//INSERT YOUR FUNCTION THAT SWAPS
//BACK/FRONT BUFFER
if (gdk_gl_drawable_is_double_buffered(glDrawable))
gdk_gl_drawable_swap_buffers(glDrawable);
else
glFlush();
//calculate alpha
alpha -= 0.01f ;
if (alpha <= 0.0f)
{
break;
}
//break ;
}
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glBlendFunc(GL_ONE,GL_ONE);
I saw the steps (Step 1 you had mentioned about)
-RENDERLOOP:
-draw scene (render the “window”)
-enable blending :
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-alpha goes from 1.0f to 0.0f for a fade to black
-glColor4f(0f,0f,0f,alpha);
-draw full screen quad
-swapbuffer
-goto RENDERLOOP
But still do not know what GL API is to be called for it. My strong point is only GTK and not GL.
Do you want to mix GTK and OpenGL rendering on the same window ?
This is probably not possible. You will have to somehow draw the GTK content on a GL texture.
So you have to :
take some screenshot of the GTK content
create a GL texture with this content
draw a textured quad with this texture in the “draw scene” step