switching scenes in program

Hi!
I want to make several scenes with different objects and movements, like they do in a demo. Someone have an idee how to do that by changing a variable or something? I tryed to use a switch statement but with no success.
(Code in c/c++) Thanks.

Do you mean that you want 1 scene display but with different items being displayed under certain conditions ? Or do you mean you want several scenes displaying different items.

If the former the following program gives you an example:

#include <gl\glut.h> //header file for GLUT

float xrot;
bool drawsqu=true;
bool drawpyr=false;

void glut_resize(int w, int h)
{
glViewport(0,0, (GLsizei) w, (GLsizei) h); // added… new window size
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,1.0,1.0,20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void glut_render(void)
{

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

glTranslatef(0,0,-5);
glRotatef(xrot,1,0,0);

if (drawpyr)
{
	glBegin(GL_TRIANGLES);
		glColor3f(1,0,0);		glVertex3f(0,1,1);
		glColor3f(0,1,0);		glVertex3f(1,0,2);
		glColor3f(0,0,1);		glVertex3f(-1,0,2);

		glColor3f(0,0,1);		glVertex3f(-1,0,2);
		glColor3f(0,1,0);		glVertex3f(1,0,2);
		glColor3f(1,0,1);		glVertex3f(0,0,0);

		glColor3f(1,0,0);		glVertex3f(0,1,1);
		glColor3f(0,0,1);		glVertex3f(-1,0,2);
		glColor3f(1,0,1);		glVertex3f(0,0,0);

		glColor3f(1,0,0);		glVertex3f(0,1,1);
		glColor3f(0,1,0);		glVertex3f(1,0,2);
		glColor3f(1,0,1);		glVertex3f(0,0,0);
	glEnd();
}


if (drawsqu)
{
	glBegin(GL_QUADS);	
		glVertex2d(-1,-1);
		glVertex2d(-1, 1);
		glVertex2d( 1, 1); 
		glVertex2d( 1,-1);
	glEnd();
}

xrot++;
glFlush();
glutSwapBuffers();

}

void mouseclick(int button, int state, int x, int y)
{
if (button == 0)
{
drawpyr = true;
drawsqu = false;
}
if (button == 1)
{
drawpyr = false;
drawsqu = true;
}
if (button == 2)
{
drawpyr = true;
drawsqu = true;
}
glutPostRedisplay();
}

int main(int argc, char **argv)
{

// Initialise
glutInit(&argc,argv);                                       //initializes the GLUT framework
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);   //sets up the display mode
glutInitWindowSize(640,480);
glutCreateWindow("Glut Test");                  //creates a window

// Functions
glutDisplayFunc(glut_render);    //specifies our redraw function
glutReshapeFunc(glut_resize);
glutIdleFunc(glut_render);
glutMouseFunc(mouseclick);


glutMainLoop();               //the main loop of the GLUT framework
return 0;

}

Hope that helps

Tina

Thanks, but there is still some questions remaining…people that makes demos, do they use a timer and switch scene after a while or how do they switch scene, automatic without a mouseclíck or keyboard input?

A timer is one option, and a good one too.

Of course you have some type of timer, else they would not change automaticaly.
You could go with how much time has passed or count the number of times the scene has been drawn.

As for changeing scenes, here is one solution:

void display()
{

if (timer_ticks > 100) scene++;

if (scene == 0 ) do_opening(); // draw opening scene
if (scene == 1 ) do_first_scene(); // draw first scene
if (scene == 2 ) do_closeing_scene(); // draw end scene.

}

Get the idea?

Originally posted by nergal:
Thanks, but there is still some questions remaining…people that makes demos, do they use a timer and switch scene after a while or how do they switch scene, automatic without a mouseclíck or keyboard input?