Fading entire screen

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.

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#Post262447

I did as suggested but the window turns black immediately with no fade effect.

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.

float alpha = 1.0f;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);

for (;:wink:
{
//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);

You totally forgot to draw your scene for each iteration.
You know the step I called “-draw scene (render the “window”)” ?

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.

Can you please add the missing pieces to the code and publish the same?

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

Any sample code for this, any pointers would do a lot of help. kind of stuck.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.