Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: problem with glutTimerFunc()

  1. #1
    Newbie Newbie
    Join Date
    Mar 2013
    Posts
    1

    Question problem with glutTimerFunc()

    try to rotate object with this code.


    main()
    {
    .
    .
    .
    NextRotate(left);
    .
    .
    .
    }


    NextRoate(move where)
    {
    .
    .
    .
    .
    .

    glutTimerFunc(33,TimerFunctionroateEach, where);
    }

    TimerFunctionroateEach(where)
    {
    ..
    .
    left? angle goes down (angle-=1)
    right? angle goes up (angle+=1)


    //slowly move until angle have been moved 90'

    if(angle%90!=0)
    TimerFunctionroateEach(angle);
    .
    .
    }

    RenderScen()
    {
    ..
    .
    .
    glRotatef(angle,1.0,0.0,0.0);
    .
    .
    .
    }






    above code works well.
    it shows how object rotate slowly, not just show how it become.

    BUT when i try to rotate more than 2, like below code.






    main()
    {
    .
    .
    .
    NextRotate(left);
    NextRotate(left);
    NextRotate(right);
    .
    .
    .
    }

    // other code are same.


    it's not work like function to function.

    i expected to rotate left first, AND THEN left again, AND THEN right rotate.

    BUT it works like all NextRoate() functions works at once, so i just can see part of last rotate (right).

    want to rotate one by one. plz help me...

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Posts
    894
    Please use [ code], [ /code] tags around source snippets (no space after '[').

    Images are only rendered after you've entered the glut main loop and even then only in response to certain OS events (e.g. window resize, etc.) or when requested with glutPostRedisplay(). Instead of a timer function you should probably use an idle function (i.e. one that is registered with glutIdleFunc). That function increments/decrements the angle, reverses direction if you hit +/- 90 degrees and ends with a call to glutPostRedisplay().

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •