I have problem with smooth animation when using SDL and OpenGL. This problem
appears even with very simple animations. I described it few months ago here,
but now I will give you example.
I modified SDLgears application a little. As you can see in SDLgears code -
gears speed depends on CPU or gfx speed. How to make it independent? I’ve
modified idle() function with SDL_GetTicks() call.
Please test if this problem appears on your system, too:
-
Download SDLgears from SDL homepage
(http://www.libsdl.org/opengl/SDLgears-1.0.2.tar.gz) -
Apply following patch:
---------cut here---------
— SDLgears.c Mon Jul 24 22:52:59 2000
+++ SDLgears-jp.c Mon Apr 29 06:10:49 2002
@@ -44,6 +44,7 @@
#endif
static GLint T0 = 0;
+static GLint t,last_t = 0;
static GLint Frames = 0;
@@ -216,7 +217,8 @@
Frames++;
{
-
GLint t = SDL_GetTicks();
-
last_t=t;
-
t = SDL_GetTicks(); if (t - T0 >= 5000) { GLfloat seconds = (t - T0) / 1000.0; GLfloat fps = Frames / seconds;
@@ -231,7 +233,7 @@
static void
idle(void)
{
- angle += 2.0;
- angle += (t-last_t)/50.0;
}
/* new window size or exposure */
---------cut here---------
-
Compile and run ./SDLgears
On my system animation is very unsmooth. Gears “stutter”. -
Add:
SDL_Delay(20);
to idle() function.
-
Compile and run ./SDLgears
Animation is perfectly smooth now!
How can you explain that? I also tried adding SDL_Timer instead SDL_GetTicks(),
with exactly same result. Is it any other way to make gears speed same on every
system? By adding SDL_Delay() I lose a lot of CPU time!
You may say, that the problem is in “int” - there is small error every time, so
there is huge sum of errors. So I tried “angle=t/50.0” (without add) - nothing
changes.
My system is Linux-2.4 with XFree86-4
Hardware: K6-2 500, Voodoo3
I thought it is tdfx related, but few days ago I have seen similiar effect on
Radeon and Duron 1000.
Please answer, I really need to know what is happening there…