I GL_QUAD texture on GL_QUAD , I start the motion animation. When moving the texture moves jerky. Drawing is in a separate stream, it is worth 1 m sleep, the time between frames is 0 - 15 msec.

It seems to be a common problem when programming 3D graphics. The fall of framerate on gpu, but so far nothing is clear.

How to avoid it?

Checked on Delphi, Qt, OpenFrameworks.

  • 2
    in graphics programming there is such a thing as double buffering .. read about it and you will find a solution to your problem .. - Alexander Molofeev
  • 3
    Double buffering does not save. Judging by the various forums problems with synchronization by timer. sim0nsays.livejournal.com/11847.html - this is how I understood the solution, but I still understand it (. - IonRod

4 answers 4

In such cases, the Draw/Update cycle is usually organized. I will give an example:

 // Π² Π½Π°Ρ‡Π°Π»Π΅ прилоТСния ΠΏΡ€ΠΈ ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ: lastUpdateTime = GetCurrentTime(); // ... // ΠΊΠΎΠ΄ рСгулярно Π²Ρ‹Π·Ρ‹Π²Π°Π΅ΠΌΠΎΠ³ΠΎ ΠΌΠ΅Ρ‚ΠΎΠ΄Π° // (Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, Ρ†ΠΈΠΊΠ» ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ сообщСний) void DoWork() { now = GetCurrentTime(); while (lastUpdateTime + updateStep <= now) { Update(); lastUpdateTime += updateStep; } Draw(); } 

where updateStep is the time allotted for the logic update step; usually equal to 1000 / FramePerSecond , if measured in milliseconds.

In the Update() method, we update the state (in this case, the motion tween), and in the Draw() method, we draw the scene.

To organize a similar method, I think, is not difficult.

    There were problems with the timer, partially solved. The system timer is buggy, it is necessary to average over time, take 10 frames of the last and take the average for this time. On half of the computers. It helped, on the other not (.

    • "This is not a bug, this is a feature!". The system timer has low accuracy for graphics, about 16ms. AlexeyM gave the correct answer. - Kromster

    If the OS is windows, then: if you specify a number (in this case, 1 ms) as a parameter of the sleep () function, then the stream will β€œsleep” from 1 to <any number of ms, as the stream manager decides. If you need to get as close as possible to the "sleep" time (sleep ()), then you can try the following:

     #include <windows.h> ... timeBeginPeriod( 1 ); // Π² мсСк ... //ваш ΠΊΠΎΠ΄ ... timeEndPeriod( 1 ); //Π’ Ρ„Π°ΠΉΠ» ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π° ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡ΠΈΡ‚ΡŒ Π»ΠΈΠ±Ρƒ LIBS += -lwinmm 

      The problem can be solved by multiplying all calculations by n \ number of frames in t seconds.

      Where experimentally pick n and t.

      something like this n = average number of frames (on the machine where it was written for) T = 0.1 sec. up to 1 sec.