Hi,
I have made a lot of performance testing with SDL and the results was
(strangely) very poor. One of that just draw 2 images one after another, in
a loop, until you close the SDL window. I’m using the 1280x800 window
resolution. In my test (code below) the frame rate doesn’t exceed 17,8 FPS,
what is a very low frame rate, since most games uses between 30 and 60 FPS
(usually). My computer is a core2 duo, 2GB RAM running Ubuntu 10.04 /
Windows 7. The glxgears runs at 432 ~ 476 FPS, and I can run well some games
like OpenTTD, Battle for Wesnoth, Warcraft III, 0 AD, Mupen64 emulator,
among others. I can’t think that this is the normal performance of SDL since
I have seen many games done with it, and they run very well in my machine
(like OpenTTD and Battle for Wesnoth). This simple test is the minimum I can
expect from SDL to run well, whereas a true game with heavy processing
routines will require much more CPU power (like the OpenTTD simulator game).
Drawing little images within a smaller window results me in a maximum of 76
FPS, but I think it’s normal to redraw big screen parts and get a frame rate
of at least 30 FPS. I have done these tests in another machine, Dual core,
2GB RAM, running Ubuntu 11.04 and the results are even worse (9 FPS, 38 FPS
maximum with little images and low screen/window resolution). I don’t know
if I’m doing something wrong, If anyone have any idea, please help me fix
this performance. I tried to change the SDL_SetVideoMode flags to
SDL_HWSURFACE with no results. The program counts the number of screen flips
(frames) and if you run with
$time ./exec
you can divide the count by the running time yielded, getting the frame rate
in frames per second (FPS).
Here is my code:
#include “SDL/SDL.h”
#include “SDL/SDL_image.h”
int main()
{
// initialize video
if(SDL_Init(SDL_INIT_VIDEO) < 0) exit(1);
SDL_Surface* screen = SDL_SetVideoMode(1280, 800, 16, SDL_SWSURFACE);
if(screen == NULL) exit(1);
bool quit = false;
SDL_Surface** img = new SDL_Surface*[2];
img[0] = IMG_Load("big.png");
img[1] = IMG_Load("big2.png");
int frames = 0;
int index = 0;
while(!quit)
{
// clear screen
SDL_Rect rect = {0, 0, 1280, 800 };
SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, 0, 0, 0));
// draw random image
index = (index == 0 ? 1 : 0);
SDL_Rect r = { 0, 0, 0, 0 };
SDL_BlitSurface(img[index], NULL, screen, &r);
// flip
SDL_Flip(screen);
frames++;
// check exit
SDL_Event event;
while(SDL_PollEvent(&event))
if(event.type == SDL_QUIT)
{
quit = true;
break;
}
}
printf("total frames: %d\n", frames);
return 0;
}
Built with:
g++ -o exec main.cpp -lSDL -lSDL_image
The test images are attached, but any PNG with 1280x800 would work.–
Yuri
-------------- next part --------------
A non-text attachment was scrubbed…
Name: big.png
Type: image/png
Size: 23730 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20111015/ce7bbed5/attachment.png
-------------- next part --------------
A non-text attachment was scrubbed…
Name: big2.png
Type: image/png
Size: 23552 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20111015/ce7bbed5/attachment-0001.png