views:

322

answers:

3

I would like to render two scenes in OpenGL, and then do a visual crossfade from one scene to the second. Can anyone suggest a starting point for learning how to do this?

Cheers

+6  A: 

The most pmajor thing you need to learn is how to do render-to-texture.

When you have both scenes in 2 textures it really is simple to crossfade between them. In fact its pretty simple to do all manor of interesting fade effects :)

Goz
Thanks, I'll look into render-to-texture. I thought about that, but wasn't sure what kind of impact it might have on performance.
BrenMcGuire
These days it doesn't. You wouldn't be able to do most fullscreen effects without it.
Goz
Too bad EXT_framebuffer_object is still stuck in extension hell :(
genpfault
It's not, see OpenGL 3.2 core specification, page 219: http://www.opengl.org/registry/doc/glspec32.core.20090803.pdf
Malte Clasen
+1  A: 

Here's sample code of a cross fade. This seems a little different than what Goz has since the two scenes are dynamic. The example uses the stencil buffer for the cross fade.

zooropa
Thing is .. the Rage 128 was released over 10 years ago. Render-to-texture didn't work well in those days. It is much easier to render scene A to texture A, render scene B to texture B and then render texture A and texture B to the frame buffer. Added bonus is that its such a common code path that it is optimised to hell and provide ALL sorts of interesting effects. The sort of stencil buffer trickery you suggest does work well but is not what most developers do and thus WILL be slower as well as far more complex.It does work though :)
Goz
I found that link before I posted the question, but it wasn't the cross-fade effect I was looking for (it's not what I would even call a cross-fade).
BrenMcGuire
A: 

I could think of another way to crossfade scenes, but it depends on how complex your scene renderer is. If it is simple, you could start a shader program before rendering the second scene that does the desired blending effect. I would try glBlend (GL_ALPHA, GL_ONE_MINUS_SRC_ALPHA) and manipulate the fragments' alpha values in the shader.

FBOs are btw. available for years already - extension or not. If your renderer is complex and uses shader programs, you could just as well render both scenes to FBOs and blend these. Using FBOs is a very common technique for allowing to easily apply all kinds of effect rendering.

karx11erx