I ?ve been reading the article about hardware surfaces with SDL on
O`reilly network witch was mentioned in the list some time ago (it?s in
the FAQ too i think, but here?s the URL
http://linux.oreillynet.com/pub/a/linux/2003/08/07/sdl_anim.html?page=1)
Well, although I couldn?t find the file ‘hardline.cpp’ alluded in the
article, it was not difficult to code using a previous version using
sorftware surfaces.
(I got it from a previous article:
http://linux.oreillynet.com/pub/a/linux/2003/05/15/sdl_anim.html)
I?ll get into the point
With the help of a frame counter and using the clock class included in
the original code I compute the FPS, and it doesn?t goes beyond 35 - 37 FPS
I?m using windows i?m doing something wrong? I belive that I should get
at least 60FPS or more (depending of mi refresh rate) or am I wrong?
Here?s the code (not included init, I?m pretty sure that I get a
fullscreen hardware surface, checked)
Frame counter located at the very end.
---------------------------CODE----------------------------
while (!done)
{
// Loop while reading all pending event.
while (!done && SDL_PollEvent(&event))
{
switch (event.type)
{
// Here we are looking for two special keys. If we
// get an event telling us that the escape key has
// been pressed the program will quit. If we see
// the F1 key we either start or stop the
// animation by starting or stopping the clock.
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_ESCAPE:
done = true;
break;
case SDLK_F1:
if (gt.stopped())
{
gt.start();
}
else
{
gt.stop();
}
break;
default:
break;
}
break;
// The SDL_QUIT event is generated when you click
// on the close button on a window. If we see that
// event we should exit the program. So, we do.
case SDL_QUIT:
done = true;
break;
}
}
// Erase the old picture by painting the whole buffer
// black.
SDL_FillRect(screen, NULL, black);
// Get the current game time. Note that if the clock
// is stopped this method will return the same value
// over and over.
int t = gt.time();
/*
rl->update(t);
gl->update(t);
bl->update(t);
//*/
// Since I'm using a software buffer the call to
// SDL_Flip() copies the software buffer to the
// display. That gives you the effect of double
// buffering without asking for it and without the
// speed you would get from a hardware double buffered
// display.
if (SDL_MUSTLOCK(screen))
{
if (-1 == SDL_LockSurface(screen))
{
printf("Can't lock hardware surface\n");
exit(1);
}
}
// Based on the current time update the location of
// each line and draw the line into the buffer.
rl->update(t);
gl->update(t);
bl->update(t);
if (SDL_MUSTLOCK(screen))
{
SDL_UnlockSurface(screen);
}
SDL_Flip(screen);
frames++;
}//end of while loop
// I added this
gt.stop();
//My frame counter//////////////////////////////////////
printf(“Frames: %d\n”, frames);
printf(“Elapsed time (miliseconds): %d\n”,gt.time());
printf(“FPS: %d\n”, (frames / (gt.time() /1000) ) );
// When we get here, just clean up and quit. Yes, the
// atexit() call makes this redundant. But, it doesn’t
// hurt and I’d rather be safe than sorry.
SDL_Quit();
}
---------------------------CODE----------------------------
Any help appreciated, and excuse my terrible english
Regards–
Ricardo Amores Hern?ndez
ICQ: 19463735
MSN: zheo_ (at) hotmail (dot) es