Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: timerfunc

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2016
    Posts
    10

    Cool timerfunc

    I am using the glutTimerFunc() command, I also know it is depracated but it will work for me at the moment. I am stubbing out some code. I am able to get a polygon to move across the top of the screen. it skips across the top of the screen, once drawn every other width of the polygon. what I want to do is draw a polygon and then erase it and then draw a polygon next to it and then erase it as well. then draw a polygon two spaces over and then erase again. I am close to solving this problem. Let me know if you need more explanation.

  2. #2
    Junior Member Newbie
    Join Date
    Oct 2016
    Posts
    10
    I am making space invaders like game, I am trying to draw bugs along the top of the screen

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2016
    Posts
    10
    could I please get a response to my post, I don't think it is a very hard question to answer.

  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,123
    Quote Originally Posted by phil67rpg2012
    could I please get a response to my post, I don't think it is a very hard question to answer.
    Unless I missed it, you didn't ask a question. You just told us what you wanted to do and said that you were close to solving your problem.

  5. #5
    Junior Member Newbie
    Join Date
    Oct 2016
    Posts
    10
    how do I draw a polygon and then wait and then erase it and then redraw it one space over. I am unsure of how to get the wait period to work. I am trying to ask a accurate question but I am unsure of how to ask it appropriately.

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,683
    You don't.

    You redraw the entire scene with the polygon you wish to move in a different position. That's how games have done it since the 1990s.

  7. #7
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,123
    Quote Originally Posted by phil67rpg2012 View Post
    how do I draw a polygon and then wait and then erase it and then redraw it one space over. I am unsure of how to get the wait period to work.
    Also, while you could use glutTimerFunc to "tick" some physics along (e.g. move the object from here to here), it's probably best for a simple application to just sample a realtime clock function at the beginning of your display() method, figure out where objects should be for that point in time, and just render them there. That way there's no aliasing effects between the display rate and the timer rate.

    That said, if your physics were very expensive, you might want to update your scene at a different rate (and possibly on a different thread) than you're rendering in.

    What you definitely don't want to do is bump the object along a certain offset per frame, as that makes the velocity of your object extremely dependent on the how fast frames are being rendered (e.g. 60fps, 30fps, 1000fps, etc.). Any of the other solutions above is preferable to that.
    Last edited by Dark Photon; 06-15-2017 at 05:30 AM.

  8. #8
    Junior Member Newbie
    Join Date
    Oct 2016
    Posts
    10
    can you further explain "sample a realtime clock function"

  9. #9
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,402
    Quote Originally Posted by phil67rpg2012 View Post
    can you further explain "sample a realtime clock function"
    Use glutGet(GLUT_ELAPSED_TIME) to obtain the number of milliseconds that have elapsed since glutInit() was called. Incorporate the time into a linear equation (start+speed*elapsed_time) to obtain a value which changes at a constant rate. Use that value in a call to glTranslate() or glRotate() to make objects move or rotate at a constant speed.

  10. #10
    Junior Member Newbie
    Join Date
    Oct 2016
    Posts
    10
    cool I will work on your post GClements.

Posting Permissions

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