Try something like this. It's complete SDL program with frame-delay, but it does not draw anything.
I use it as a starting piont for an SDL-program. I took the frame-delay function from Sam Lantinga's example SDL-program "aliens". See
http://www.libsdl.org/projects/aliens/
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include "SDL.h"
#define FRAMES_PER_SEC 50
SDL_Surface *screen;
void updatescreen (void)
{
/* Draw your frame here */
}
void init (void)
{
srand (time (NULL));
if (SDL_Init (SDL_INIT_VIDEO) < 0) {
fprintf (stderr, "Unable to init SDL: %s\n", SDL_GetError ());
exit (1);
}
atexit (SDL_Quit);
screen = SDL_SetVideoMode (640, 480, 16, SDL_SWSURFACE);
if (screen == NULL) {
fprintf (stderr, "Unable to set 640x480x16 video mode: %s\n",
SDL_GetError ());
exit (1);
}
}
void framedelay (void)
{
static Uint32 next_tick = 0;
Uint32 this_tick;
this_tick = SDL_GetTicks ();
if (this_tick < next_tick) {
SDL_Delay (next_tick - this_tick);
}
next_tick = this_tick + (1000 / FRAMES_PER_SEC);
}
void run (void)
{
int done;
SDL_Event event;
done = 0;
while (1) {
framedelay ();
while (SDL_PollEvent (&event)) {
switch (event.type) {
case SDL_QUIT:
return;
}
}
updatescreen ();
}
}
int main (int argc, char *argv[])
{
init ();
updatescreen ();
run ();
return 0;
}
Compile and link with:
Code:
gcc -g -Wall `sdl-config --cflags` `sdl-config --libs` -o progname progname.c