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 8578989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:31:02+00:00 2026-06-11T20:31:02+00:00

I have tried different machines, VSync on and off. I have provided my main

  • 0

I have tried different machines, VSync on and off.

I have provided my main method and display method. In the main look I calculate delta using GLFWs GetTime method.

If I explicitly set deltaTime = 0.016 to lock the target speed, the triangle moves smoothly.

int main(int argc, char** argv)
{
    /*
        INIT AND OTHER STUFF SNIPPED OUT
    */

    double currentFrame = glfwGetTime();
    double lastFrame = currentFrame;
    double deltaTime;

    double a=0;
    double speed = 0.6;
    //Main loop
    while(true)
    {
        a++;

        currentFrame = glfwGetTime();
        deltaTime = currentFrame - lastFrame;
        lastFrame = currentFrame;

        /** I know that delta time is around 0.016 at my framerate **/
        //deltaTime = 0.016;

        x = sin( a * deltaTime * speed ) * 0.8f;
        y = cos( a * deltaTime * speed ) * 0.8f;

        display();

        if(glfwGetKey(GLFW_KEY_ESC) || !glfwGetWindowParam(GLFW_OPENED))
            break;
    }

    glfwTerminate();

    return 0;
}

void display()
{
    glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    glUseProgram(playerProgram);

        glUniform3f(playerLocationUniform,x,y,z);

        glBindBuffer(GL_ARRAY_BUFFER, playerVertexBufferObject);

        glEnableVertexAttribArray(0);
            glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
            glDrawArrays(GL_TRIANGLES, 0, 3);
        glDisableVertexAttribArray(0);

    glUseProgram(0);
    glfwSwapBuffers();

}
  • 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-06-11T20:31:03+00:00Added an answer on June 11, 2026 at 8:31 pm

    You are using deltaTime as if it was a global framerate and calculating the sine and cosine based on a frame number (a) multiplied by that rate. What that means is a minor fluctuation in deltaTime between frames will cause larger changes in position as a becomes larger.

    In the other case, where you set a constant deltaTime, you still get small glitches when a frame is rendered at the wrong time.

    What you actually need to do is this:

    #define TAU (M_PI * 2.0)
    
        currentFrame = glfwGetTime();
        deltaTime = currentFrame - lastFrame;
        lastFrame = currentFrame;
    
        a += deltaTime * speed;
    
        // Optional, keep the cycle bounded to reduce precision errors
        // if you plan to leave this running for a long time...
        if( a > TAU ) a -= TAU;
    
        x = sin( a ) * 0.8f;
        y = cos( a ) * 0.8f;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jQuery fullcalendar plugin , I have tried altering this many different
I have two different-sized monitors, connected together using (I believe) TwinView. I tried System.out.println(Toolkit.getDefaultToolkit().getScreenSize());
I have tried on two different machines, and tried the download several times, but
I have tried different methods and none of them seem to work. When I
I have a small problem, I have tried different solutions to add a image
I have tried a variety of different solutions found on stack and other places
I have tried this a few different ways and it always seems to fail.
I have searched here on SO and tried different solutions offered here, but cannot
I have one key but different values for that key. I tried HashTable but
I want to start a couple of jobs on different machines using ssh. If

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.