Skip to main content
GameDev.net gamedev.net
🔒 Locked

Transitions

Started by levjs Nov 1, 2005 at 3:28 PM 5 replies 450+ views
Original Post
levjs
levjs
Hello, I have been wondering this for some time. How would you make all the pixels on the screen turn a certain color, in effect, creating a screen that fades out from a scene, then turns white(or black), then fades into another scene. Thanks. Levi
ff8
ff8
u can change to Ortho mode then draw a quad on the whole screen after that u decrease the alpha value for the quad this will make fade in/out effect
cya,
Undeadlnsanity
Undeadlnsanity
You can use glClearColor to colour in the background of your application.

Example usage that creates a black:
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);

The first param is the red value, second is the green value, third is the blue value and fourth is the alpha value.
LilBudyWizer
LilBudyWizer
You could set the texture environment mode to GL_BLEND then fade the color of the polygons and environmental color. That's assuming you want to basically fade to black then back in with the new scene. It doesn't have to be black, but basically a fixed color.

If you want mix the images you can use the stencil buffer. With the stencil buffer you basically use a dither pattern. You draw one with the stencil test set to equal and other to not equal. That will let you do some neat wipes like a circle openning with the new image from the center of the screen until it fills the screen.

If you don't want to fade to some color then come back in as the next image then I believe you need to use the accumulation buffer. I haven't gotten that far yet, but I believe it will do a blend between two images basically like using alphas.

Overall for testing you can use viewports and scissor test to draw the sequence of images on the screen to get a rough feel for how the fades and wipes are looking. You can also use that for wipes. That's how you would do frames like in a comic book as they did in the Hulk movie.
Keys to success: Ability, ambition and opportunity.
Undeadlnsanity
Undeadlnsanity
Just had another thought about implementing the actual fading. You could use a variable for each of the values and add onto them until you reached your desired colour in a while loop. Here's how I'd do this using glClearColor():
GLfloat fade_r;GLfloat fade_g;GLfloat fade_b;int DrawGLScene(GLvoid){// ...while (fade_r < 10.0f && fade_g < 10.0f && fade_b < 10.0f ){   glClearColor(fade_r, fade_g, fade_b, 0.5f);   fade_r+=0.05f;   fade_g+=0.05f;   fade_b+=0.05f;}}


If you just want to change the "shade" of a colour instead of the actual colour itself then change the alpha value instead.

[Edited by - Undeadlnsanity on November 1, 2005 4:07:28 PM]
PuDDu
PuDDu
The Fade(int delay) method will fade out to black in delay milliseconds.
m_timer.GetTime() gives the time in milliseconds, it's the usual timer class.
m_Window.GetWidth() and GetHeght() returns the size of the actual viewport.

void cEngine::go2D(){ 	int vPort[4]; 		glGetIntegerv(GL_VIEWPORT, vPort);		glMatrixMode(GL_PROJECTION);	glPushMatrix();	glLoadIdentity();		glOrtho(0, vPort[2], 0, vPort[3], -1, 1);	glMatrixMode(GL_MODELVIEW);	glPushMatrix();	glLoadIdentity();	 }void cEngine::goPerspective(){  glMatrixMode( GL_PROJECTION );	glPopMatrix();	glMatrixMode( GL_MODELVIEW );	glPopMatrix();	 }void cEngine::Fade(int delay) //delay in millisecond{	float time = 0.0f;	float alpha = 0.0f;			glPushAttrib( GL_TEXTURE_BIT | GL_DEPTH_TEST | GL_LIGHTING );	glDisable( GL_DEPTH_TEST );	glDisable( GL_LIGHTING );		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);	glEnable(GL_BLEND);			go2D();		for (;;) 	{	 	time += m_timer.getTime();	 		 	glColor4f(0.0f, 0.0f, 0.0f, alpha);				glBegin(GL_QUADS);	      glVertex2f(0.0f, m_Window.GetHeight());	      glVertex2f(0.0f, 0.0f);	      glVertex2f(m_Window.GetWidth(), 0.0f);	      glVertex2f(m_Window.GetWidth(), m_Window.GetHeight());	  glEnd();	  		m_Window.SwapBuffers();			 	alpha = (time/delay)/1000.0f;	 		 	if (alpha >= 1.0f) 		  break;	}		goPerspective();		glDisable(GL_BLEND);	glBlendFunc(GL_ONE, GL_ONE);		glPopAttrib();	}
levjs
levjs
Hi all,
Thanks for replying.

Quote:
You can use glClearColor to colour in the background of your application.


This will only change the background color, instead of atcually changing the whole screen. Thanks for replying though.

Quote:
You could set the texture environment mode to GL_BLEND then fade the color of the polygons and environmental color. That's assuming you want to basically fade to black then back in with the new scene. It doesn't have to be black, but basically a fixed color.


That's an idea, I'll try that.

Quote:
If you don't want to fade to some color then come back in as the next image then I believe you need to use the accumulation buffer. I haven't gotten that far yet, but I believe it will do a blend between two images basically like using alphas.


Haven't gotten that far yet either. : )

Quote:
u can change to Ortho mode then draw a quad on the whole screen after that u decrease the alpha value for the quad this will make fade in/out effect
cya,


I'll try this one too.

Quote:
The Fade(int delay) method will fade out to black in delay milliseconds.

I'll also try this one.

I'll see which one works best, and which ones are easiest. Thanks for all your suggestions.

Levi

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.