PDA

View Full Version : Fading entire screen



gkp_vij
07-06-2010, 11:46 PM
Hi guys,

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?

Regards,
Vijay.

ZbuffeR
07-07-2010, 01:28 AM
The simplest is to simply draw a large black quad covering the whole window, and play with alpha to fade gradually.

Searching on these forums you will see code.

EDIT : here it is :
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=262447#Post2624 47

gkp_vij
07-09-2010, 01:47 AM
I did as suggested but the window turns black immediately with no fade effect.

ZbuffeR
07-09-2010, 03:16 AM
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.

gkp_vij
07-12-2010, 12:17 AM
float alpha = 1.0f;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);

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);

ZbuffeR
07-12-2010, 02:12 AM
You totally forgot to draw your scene for each iteration.
You know the step I called "-draw scene (render the "window")" ?

gkp_vij
07-12-2010, 02:55 AM
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.

Please advice.

gkp_vij
07-12-2010, 03:47 AM
Can you please add the missing pieces to the code and publish the same?

ZbuffeR
07-12-2010, 09:40 AM
OK I think I misread your original post.

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

gkp_vij
07-12-2010, 11:14 PM
Any sample code for this, any pointers would do a lot of help. kind of stuck.