Results 1 to 7 of 7

Thread: Timer Function

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2017
    Location
    germany
    Posts
    16

    Timer Function

    Is it possible to pass a paramter to a function inside a timer, or can the timer only do, say, update() then in the update function i pass the parameter to the function?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,649
    This doesn't sound like an OpenGL question. If it is, please post a code snippet to illustrate your problem.

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2017
    Location
    germany
    Posts
    16
    Well I dont really have any code for it. I need to write a timer function to increase an angle of a variable. So i was thinking it would be something along the lines of

    Code :
    void timer (int value){
    Display();
    glutTimerFunc(40, Timer, 0);
    }


    Or something weird like

    Code :
    void timer (int value){
    setAngle(angle){
    angle+=45;}
    glutTimerFunc(40, Timer, 0);
    }

    I am thinking i will need to post the angle increase in the display function. Im learning it in a class that is mostly teaching openGL, so assumed it was

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,649
    I think I see what you're saying now.

    I wouldn't display your scene in the timer function. Use glutDisplayFunc() to register a function that does that.

    When you want to have the display function called, call glutPostRedisplay().

    As far as the timer function to update world state, you can just have the timer callback increment a global "angle" variable and return. That's one way to do it. GLUT is really just for simple test programs, so I wouldn't get too caught up on using a global here.

  5. #5
    Junior Member Newbie
    Join Date
    Feb 2017
    Location
    germany
    Posts
    16
    Do you mean call the glutPostRedisplay in the timer. Basically the question i am trying to solve is,

    Write a timer function that will increase and angle variable by 45 degrees and pass it to setAngle function and cause the display function to be called 10 times p/s.

  6. #6
    Senior Member Regular Contributor
    Join Date
    Jul 2012
    Posts
    459
    Here is an example that does something really similar to what you want.

    One important thing to do inside the timer callback is to recall glutTimerFunc. Otherwise it will stop once the first call done.

  7. #7
    Senior Member Regular Contributor
    Join Date
    May 2016
    Posts
    477
    another way is to register the "void display()" function in which you call 2 other functions:
    Code :
    void display()
    {
     
    float frametime = ...; // for time-based animations
    updatescene(frametime);
    drawscene();
     
    }

    http://www.cplusplus.com/reference/c...tion_clock/now

Similar Threads

  1. Timer Function
    By debinair in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 09-10-2013, 12:56 AM
  2. glut timer function burns my CPU (still..)
    By jean-bobby in forum OpenGL: General
    Replies: 3
    Last Post: 06-03-2004, 07:48 PM
  3. Glut timer function burns my CPU
    By jean-bobby in forum OpenGL: General
    Replies: 2
    Last Post: 05-17-2004, 08:07 AM
  4. timer function
    By in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 12-06-2001, 09:35 PM

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