summaryrefslogtreecommitdiffstats
path: root/sdl
diff options
context:
space:
mode:
Diffstat (limited to 'sdl')
-rw-r--r--sdl/math3d.c2
-rw-r--r--sdl/pyramid.c14
2 files changed, 15 insertions, 1 deletions
diff --git a/sdl/math3d.c b/sdl/math3d.c
index cdfb8cd..7baad85 100644
--- a/sdl/math3d.c
+++ b/sdl/math3d.c
@@ -611,7 +611,7 @@ GLbyte *gltLoadTGA(const char *szFileName, GLint *iWidth, GLint *iHeight,
if (pBits == NULL)
{
perror("malloc");
- return 0;
+ return NULL;
}
/* read in the bits */
diff --git a/sdl/pyramid.c b/sdl/pyramid.c
index 90f513c..e2d317c 100644
--- a/sdl/pyramid.c
+++ b/sdl/pyramid.c
@@ -6,6 +6,8 @@
#include <SDL/SDL_image.h>
/* for some reason order of the headers matters */
#include "math3d.h"
+#include <sys/time.h>
+#define FRAMES_PER_SECOND 300
static GLfloat xRot = 0.0f;
static GLfloat yRot = 0.0f;
@@ -293,13 +295,25 @@ int main(int argc, char **argv)
Uint32 deltaclock = 0;
Uint32 current_fps = 0;
#endif
+ struct timeval m_LastCount;
+ struct timeval lcurrent;
for (;;)
{
+ gettimeofday(&m_LastCount, 0);
#ifdef STAT_FPS
startclock = SDL_GetTicks();
#endif
processEvents();
render();
+
+ gettimeofday(&lcurrent, 0);
+ float fSeconds = (float) (lcurrent.tv_sec - m_LastCount.tv_sec);
+ float fFraction = (float) (lcurrent.tv_usec - m_LastCount.tv_usec) * 0.000001f;
+ float delta = fSeconds + fFraction;
+
+ if (delta < 1000 / FRAMES_PER_SECOND)
+ SDL_Delay((1000 / FRAMES_PER_SECOND) - delta);
+
#ifdef STAT_FPS
deltaclock = SDL_GetTicks() - startclock;
if (deltaclock != 0 )