Demo structure

Hi,

I have learnt a bit about OpenGL now and I want to make a demo to show my friends what I am able to do.

But I do not know what is the best (the best doesn’t exist here, it should be “a good”) structure for a demo.

I can make 1 big render function that does if (time > 291) … for the whole demo, or I could make different sub-render functions. This does make it a little more readable, but it’s basically the same thing as 1 big render function.

Are there any other (better) ways to do this?

Thx,
Steve_

Hi steve!

I’ve done it like this:

you have one main-render function called on an idle-event (glutIdleFunc or something else…).
in this function a timer-variable is calculated (easiest: iTimer++; or by retrieving timer-ticks or so from the system, thats good if you want, that your demo run’s at the same speed on different systems…). then, a variable exists, which holds the number of the scene I want to draw. the main render functionb calls some sub-functions and give the timer to them. the sub-function returns with “0” if the scene isn’t finished and with “1” if finished, and then the next scene is processed. some examplecode

int timer=0;
int scene=0;
void display()
{
int b;
timer++;
switch(scene)
case 0: b=scene_no1(timer);
if (b==1) scene++;
break
case 1: .
.
.
.
.
.and so on…
}
int scene_no1(int timer)
{
//bla…render stuff here
if (scene_is_finished==true) return 1; else return 0;
}

hope this helps a bit. It makes your code more readable, and is MUCH better for debugging… believe me ;> it could save a lot of time…

Bastian

What I had in mind was something like this:

A main render function, which is called every frame which calls sub-render functions.

void main_render()
{
if (time >= 10 && time < 20)
render1();
if (time >= 20 && time < 30)
render2();


}

Thats nearly similar to my description. the better thing in my system is, that every scene tells the main function when it’s finished…