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

  • SEARCH
  • Home
  • 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 7459035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:56:03+00:00 2026-05-29T13:56:03+00:00

i’m programming a little game with opengl and C. I’ve encountered an issue: due

  • 0

i’m programming a little game with opengl and C.
I’ve encountered an issue:
due to clipping… my animation (actually based on glutTimerFunc) haven’t a constant fps.
A variable fps isn’t a problem, but the animation is affected, so it don’t correspond to the timing, then: fps1,pos1; fps2,pos2; fps3,pos3…
But if the fps isn’t regular, so animation doesn’t.
I would implement it like: fps1,pos1;(if fps1 isn’t drawed) fps2,pos1; (fps1 drawing ended, so now, because i skipped a frame) fps3,pos3.

how can i do it? i would use the clock() function, but it gives always 0

ps: howto force v-sync in opengl?

  • 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-29T13:56:05+00:00Added an answer on May 29, 2026 at 1:56 pm

    Whether OpenGL updates are synchronised with the vertical retrace will be communicated in an platform-specific manner since it’s related to however your platform has tied OpenGL into itself. So it’s a tick box in the interface designer on the Mac, there’s a WGL extension called WGL_EXT_swap_control over on Windows and a GLX extension in X11.

    Assuming you have some means of installing a callback that is triggered upon vertical retrace (such as via a CVDisplayLink on the Mac; sadly I’m not up on the Windows/Linux equivalents), and you want your physics to run at a constant number of steps per second, you could write something like:

    void myRetraceFunction()
    {
        static unsigned int timeError = 0;
        static unsigned int timeOfLastFrame = 0;
    
        unsigned int timeNow = getTimeNow(); // assume this returns in ms
    
        // Get time since last frame.
        // Since we ignore overflow here, we don't care that the result of
        // getTimeNow presumably overflows.
        unsigned int timeSinceLastFrame = timeNow - timeOfLastFrame;
    
        // Store this so that we get correct results next time around.
        timeOfLastFrame = timeNow;
    
        // Establish the number of times to update physics per second, as the
        // name says. So supposing it has been 0.5 of a second since we last
        // drew, we'd want to perform 0.5*200 physics updates
        const unsigned int numberOfTimesToUpdatePhysicsPerSecond = 200;
    
        // calculate updates as (updatesPerSecond * timeSinceLastFrame / 1000),
        // because we're assuming time is in milliseconds and there are 1000
        // of them in a second. What we'll do though is preserve any amount we'd
        // lose by dividing here, so that errors balance themselves.
        //
        // We assume that timeSinceLastFrame will be small enough that we won't
        // overflow here.
        unsigned int timeSinceLastFrameNumerator =
              timeSinceLastFrame * numberOfTimesToUpdatePhysicsPerSecond
              + timeError;
    
        // calculate how much of the numerator we're going to lose to
        // truncation, so that we add it next frame and don't lose time
        timeError = timeSinceLastFrameNumerator % 1000;
    
        // calculate how many physics updates to perform
        unsigned int physicsUpdatesToPerform = timeSinceLastFrameNumerator / 1000;
    
        // do the physics work...
        while(physicsUpdatesToPerform--)
           updatePhysics();
    
        // ... and draw a frame
        drawFrame();
    }
    

    That timeError stuff is to regulate against rounding problems. E.g. suppose you were running at a constant 70 frames a second and wanted physics updates 60 times a second. If you ignored the error that accumulates then you’d actually run zero physics updates a second since at each instant the code would come to the conclusion that the amount of time since the last frame draw wasn’t long enough for a physics update to have been required. And you’d also otherwise get aliasing problems if you went the other way, with any frame rate that isn’t an integer divisor of the physics update rate.

    If you don’t have an explicit retrace function but instead a perpetual loop that pushes out frames but blocks on vertical retrace then you’d write the same sort of thing.

    If you have no way to block on vertical retrace at all, you might install a timer at a target frame rate and pretend that’s a vertical retrace sync. You could just push frames out as fast as possible but you’ll likely get complaints with anyone with a laptop or other machine where it’s pretty obvious when the fans are coming on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

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.