PDA

View Full Version : basic scene changing



someone_else
12-26-2003, 09:17 PM
I'm pretty new to OpenGL, but I've gone through most of NeHe's tutorials. I am attempting to work on my first project, and I had a question.

For example: I want to make a short movie that is composed of two scenes. The first scene shows the title of the movie, and the second scene shows a rotating cube.

Is there a tutorial that explains how to do this? I know how to do the different things in 2 separate executables, but what is the standard procedure for doing something like that in 1?

Do I set up each 'scene' in it's own function and call them according to a certain counter? Confusion! http://www.opengl.org/discussion_boards/ubb/frown.gif

- Thanks in advance~

PanzerSchreck
12-27-2003, 12:12 AM
That's best done with a finite state machine, that goes something like this (bit of Pascal, but should be easy to read http://www.opengl.org/discussion_boards/ubb/wink.gif ) :


const
StateFirstScene = $01;
StateSecondScene = $02;
var
CurrentState : Word;
...
procedure DrawFirstScene;
...
procedure DrawSecondScene;
...
case CurrentState of
StateFirstScene : DrawFirstScene;
StateSecondScene : DrawSecondScene;
end;

At least that's the most obivious and easiest way to show two totally different scenes in one app.

zeckensack
12-27-2003, 12:24 AM
What PanzerSchreck said http://www.opengl.org/discussion_boards/ubb/smile.gif

I just wanted to add that you must of course provide for some transition between states. Eg if your "intro" is supposed to play for ten seconds, you must change the state when it has finished playing.

I usually tackle this by making scene rendering functions return a boolean that indicates whether they are finished or not.

"Main loop" code would look something like this


switch (current_scene)
{
case(0):
if (render_scene_0())
{
//still playing ...
}
else
{
//finished
//free scene 0's data
//transition to scene 1
current_scene=1;
}
break;
case(1):
if (render_scene_1())
.
.
.
break;
}

nexusone
12-27-2003, 05:38 AM
There are many way's in which you can do this, all require some type of timmer to tell when to change scenes.

1. Using diffrent routines:

void display(void)
{

if (time <= 1 ) draw_scene_1();
if (time > 1 ) draw_scene_2();

}


2. You can also create a simple script in which to tell your program what to display at what time in the program. And track some type of frame or time variable.