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

From what I know, everything about OpenGL changed since 3.1 and now I can't
I'm trying to add embedded python to a OpenGL/SDL application. So far everything works
I made a simple game for the iPhone using OpenGL ES. Everything works fine
The Problem (TL;DR) My problem, fundamentally, is that I do not know how OpenGL
I'm working in an openGL for iPhone , and although everything works great I
I'm drawing text in OpenGL using FTGL library and everything works just fine, however
I have an opengl canvas and lightweight menus set to false, and everything works
I want to draw text with OpenGL using FreeType and to make it sharper,
I'm just using the opengl SDL template with Xcode, and everything runs fine. I
Does anyone know or have good links that explain what iPhone's event loop does

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.