1
\$\begingroup\$

I have a coded a simple example for a matrix rotation. The example rotates a sphere around its center. The problem is that the rotation is not running perfectly smooth and I'm wondering why.

Here is a minimal code sample:

float totalMs = 0.0f;
int animationDuration = 5000;

void update(float deltaMs) {
    totalMs += deltaMs;
    float degrees = (totalMs % animationDuration) / animationDuration * 360.0f;
    glm::mat4 rotation = glm::rotate(glm::mat4(), radians(degrees), rotationAxis);

    //multiply modelViewMatrix by rotation matrix
    //and use the resulting matrix in shader to transform points
}

I'm programming in C++, using GLM Library for Maths, SDL2 for rendering context and OpenGL for the rendering.

Any hints what could cause the rendering to not look totally smooth?

Edit: Ok I found out that the time needed for SDL_GL_SwapWindow() at the end of my gameLoop varies between <1ms and >30ms. What could be causing this?

\$\endgroup\$
4
  • \$\begingroup\$ What are usual values of deltaMs here? Are you sure it is not a framerate problem? \$\endgroup\$
    – Aracthor
    Sep 28, 2015 at 0:55
  • \$\begingroup\$ Looks like the deltaMs could be jittery/non-smooth. \$\endgroup\$
    – Kromster
    Sep 28, 2015 at 16:08
  • \$\begingroup\$ You are right its because of the deltaMs, I made an edit to the question. Any Ideas? \$\endgroup\$
    – D-rk
    Sep 28, 2015 at 20:27
  • \$\begingroup\$ You should reformulate and rename your question to reflect the problem. \$\endgroup\$
    – Kromster
    Sep 29, 2015 at 5:11

1 Answer 1

1
\$\begingroup\$

If you have v-sync enabled ( SDL_GL_SetSwapInterval(1) ), SDL_GL_SwapWindow will wait until your monitor refreshes.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .