我尝试过不同的机器,打开和关闭 VSync。
我提供了我的主要方法和显示方法。在主要外观中,我使用 GLFWs GetTime 方法计算增量。
如果我明确设置 deltaTime = 0.016 来锁定目标速度,三角形会平稳移动。
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();
}