PDA

View Full Version : best way to do animation/updates in GLUT



Froofy-D
06-24-2003, 11:08 AM
After looking at a lot of code I see many people handle scene updates in GLUT differently. It usually invoves either glutPostRedisplay() or glutIdleFunc(). Just wondering which is more optimal, or is there a better way? I'm using VC++ and GLUT and making simple Dos executables.

Example 1: *****************************

void display()
{
//update your objects and draw them
glutSwapBuffers();
glutPostRedisplay();
}

void main()
{
// do initialization here etc...
glutDisplayFunc(display);
}

or Example 2: *****************************

void display()
{
//update objects and draw scene
glutSwapBuffers();
}

void main()
{
// start openGL loop...
glutDisplayFunc(display);
glutIdleFunc(display);
}

***************************************
Is either method "better" or does it make a difference? Or is there a more optimal way?

06-24-2003, 06:36 PM
I think glutIdleFunc should be little better because no messages has to be sent. The difference is probably very small.

nexusone
06-25-2003, 05:22 AM
Remember some examples are just examples just to show how a function work, maybe not the best aproach.

I think you have to look at what your end program is going to be doing, if you just want to spin a cube that really does not make too much diffrence how you do it. But then you get to a advanced program then you do have to look at each section and timming becomes important.

Both of you examples are so close I don't think that it would make much diffrence.

I like to break thing down into sections, which in a large program will come in handy when trying to get the bugs out.


Program flow:

// Start of program
void main(......)
{
// setup glut window stuff
GLinit()
// Init variables
init();
// start glut
glutMainLoop();
}

void My_display(void)
{
// Pull all drawing calls in here

glutSwapBuffers();
}

void My_idle_event(void)
{
// Update object positions
// Update variables

glutPostRedisplay();
}

Also take a look at some of my glut examples on www.angelfire.com/linux/nexusone/ (http://www.angelfire.com/linux/nexusone/)