Results 1 to 3 of 3

Thread: best way to do animation/updates in GLUT

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2003
    Location
    Orlando, FL US
    Posts
    2

    best way to do animation/updates in GLUT

    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?

  2. #2
    Guest

    Re: best way to do animation/updates in GLUT

    I think glutIdleFunc should be little better because no messages has to be sent. The difference is probably very small.

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: best way to do animation/updates in GLUT

    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/

Similar Threads

  1. GL2 2D animation w/o GLUT... I think I almost got it?
    By NathanHawks_US in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-30-2017, 03:55 PM
  2. Animation with glut
    By debinair in forum OpenGL: Basic Coding
    Replies: 10
    Last Post: 09-07-2013, 12:21 AM
  3. how to do animation using glut
    By qawded in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 07-08-2013, 12:49 AM
  4. glut & animation?
    By apocalexiz in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-17-2003, 05:16 AM
  5. Gtk and Glut animation
    By Mao in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 04-30-2003, 05:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean