Results 1 to 2 of 2

Thread: problem with Sleep( ) in glut

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2001
    Location
    Islamabad,capital,Pakistan.
    Posts
    14

    problem with Sleep( ) in glut

    I am have made a 2D app in glut, which updates after a change in the functionality of the program. The problem is that if I want to run the program in a loop instead of initiating it manually the functions execute so quickly that it doesnt show. In order to slow it down I use Sleep( ) function after every glutPostRedisplay() funtions but the problem is that the screen freezes when I call Sleep( ). Another thing is that I manually update the program through pop-up menu. Has the pop-up menu got anything to do with this problem?
    Please help.
    Only Human

  2. #2
    Senior Member Regular Contributor
    Join Date
    Jul 2001
    Posts
    352

    Re: problem with Sleep( ) in glut

    The problem is that you should never use a Sleep-like function to slow down a program. You have to find other ways. Possibilities include :
    1) make a "timer callback" : that is, ask to GLUT to call a function of your choice every x milliseconds.
    2) before doing an action that has to be done "not too fast", measure the elapsed time since the last time you did it. Then, adapt this action to this time.

    If it's for graphical animation, 2) is definitely the right way. the glut code could look like :

    float position_of_object;

    void display ()
    { ...
    float elapsed_time = measure_elapsed_time ();
    position_of_object += a_constant * elapsed_time;
    draw_object (position_of_object);
    glutPostRedisplay ();
    }

    void main (int argc, char *argv[])
    { ...
    glutDisplayFunc (display);
    }

Similar Threads

  1. OpenGL goes to sleep
    By kris in forum OpenGL: Windows
    Replies: 5
    Last Post: 04-23-2011, 06:16 PM
  2. Sleep in openGL
    By enigmatic in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 05-13-2010, 05:51 PM
  3. sleep necessary?
    By B OBAMA in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 05-07-2008, 02:27 AM
  4. GLUT Problem
    By bra-ket in forum OpenGL: General
    Replies: 7
    Last Post: 02-09-2004, 07:59 PM
  5. Help! Problem about Glut
    By Dickie in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-21-2003, 06:38 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