Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4554656
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:06:58+00:00 2026-05-21T17:06:58+00:00

In OpenGL, everything works with the main loop (as far as I know). This

  • 0

In OpenGL, everything works with the main loop (as far as I know). This is a problem if you want to draw an object for given time. For now, what I do is the following: I measure the approximate FPS of my application and set up a counter that I decrease at every iteration in the main loop. When the counter reaches 0, I stop drawing. So for example if I want to draw an object for 2s on the screen, and my FPS is 30, I set up the counter to 60 and draw the object until the counter reaches 0.

This works OK, but it’s not great. For example, it makes it hard to write something like
drawObjectFor(object, time) since the object is sometimes “far” from the main loop. Is there a better way to do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T17:06:59+00:00Added an answer on May 21, 2026 at 5:06 pm

    Your FPS may (and usually will) vary, so counting frames is not a great idea.

    Assume this example to see how this could bite you:
    Your application runs vsynced to 60 FPS, and your frame time is 16.58ms. That means to have the object on screen for 2 seconds, you will have to draw your object for 120 frames. Easy, let’s go!
    Drawing the object adds 0.1 ms, giving a total frame time of 16.68ms. Oh sh*t. Now you have 30 FPS, and your object shows for 4 seconds…

    Use proper time to decide whether or not to draw your object. When you’ve reached the conclusion that your object’s time is up, just set a flag so you won’t draw it (or, remove it from the scenegraph, if you have one, or delete it, or whatever).

    This can be done in a variety of ways:

    • Under Windows
      • Use SetTimer, which will post a message to your window’s message queue. When you receive the WM_TIMER notification, set the object’s do_draw flag (or whatever you want to call it) to false.
      • If you already use WaitFor(Single|Multiple)Object somewhere once every frame, do a CreateWaitableTimer, and wait on this as well. You can use MsgWaitForMultipleObjectsEx to do the message pumping and waiting in one go, and check APCs at the same time.
      • Nothing prevents you from reading time manually once per frame. GetTickCount once, add 2000, and do an if(new_count <= old_count + 2000) draw_object(). While the accuracy of GetTickCount is abysmal (several dozens of milliseconds), this does not matter at all when waiting for 2 seconds.
    • Under Linux
      • Use a timerfd and an epoll to check readiness, or set the timerfd it to nonblocking and see whether reading from it returns EAGAIN
      • Use clock_gettime and do it manually (as with GetTickCount)
      • Use setitimer
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the opengl section of Hillegass' otherwise fine book, we're given sample code for
I'm making a 3D FPS with OpenGL and here is the basics of how
I'm trying to make a vector drawing application using OpenGL which will allow the
I'm new to opengl and have been able to learn a lot on my
I have a normal VS2008 project that I've been working on for awhile that
I'm am working on a basic augmented reality application on Android. What I did
I'm making a game which requires multiple images to be drawn on the screen.
I'm calculating the Euclidean distance between n-dimensional points using OpenCL. I get two lists
What I'm trying to do is output a masked texture on an iPhone using
I'm writing a 2d tile-based engine. Currently, my drawing routine uses the C# Drawing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.