SDL Question

Started by
6 comments, last by Nairb 22 years, 2 months ago
Hey, Sorry I''m posting this question here, but there doesn''t seem to be a forum for SDL, and I''ve been racking my brain for hours now. I have a program. It''s a remarkably simple program - all it does is blit a bunch of tiles to the screen within a nested for loop. Normally, in DX, I can pull off about 100 FPS with something so simple. However, I''m getting 30 with SDL. I have a friend. He has a program in SDL that is much more complicated, and his program is running at 150 FPS. However, when he runs my program, it''s still 30 FPS. This leads me to believe that there must be some flaw within my code. However, I can not find ANYTHING that could possibly cause such an effect. If anyone has any information on this topic that could help me, I would greatly appreciate it. Here''s a general outline of what the progrma does: Initialize video to 640*480*16 Start main loop --During each iteration-- Check an event. Quit if escape is hit or window is closed. Run a loop that draws 16*16 tiles all acrss the screen. --end loop-- release everything necessary. I, unfortunately, can not see any flaws with the code. I''m only using standard SDL stuff - no other libraries. It''s version 1.2.3. Thanks, --Nairb
Advertisement
2 suggestions:
1) Specify SDL_DOUBLEBUF and SDL_HWSURFACE flags to SDL_SetvideoMode
P.S. When using the hardware double buffer for the blit, use the method SDL_Flip( surface ) instead of SDL_UpdateRect.

2) Use SDL_DisplayFormat( surface ) to convert an image into an optimal format for FAST blitting.

I hope this helps to increase your framerate.
Good luck.
Hey,
Thanks for the help... the second tip sped things up a lot. Unfortunately, however, the FPS is still unacceptable. :-(
Anyone else have any pointers?

Thanks,
--Nairb
I''ve run into this exact problem, just rendering tiles, I get less then 15 fps.
Switching to allegro I get more than 140 fps, so it''s not a slow pc problem.

With mine I used SDL_Flip, and SDL_DOUBLEBUF | SDL_HWSURFACE and it slowed down more for some reason.
Are you calling SDL_SetColorKey() anywhere? If you are, maybe you should try using SDL_SetColorKey(surface, SDL_SRCCOLORKEY|SDL_RLEACCEL, SDL_MapRGB(ball->surface, 0, 0, 0));
RLEACCEL supposedly makes the image blit faster ( I got +2 FPS () when I used it). Just a thought.


------------------------------
Simple DirectMedia Layer:

Main Site - (www.libsdl.org)
Cone3D Tutorials- (cone3D.gamedev.net)
GameDev.net''s Tutorials - (Here)

OpenGL:

Main Site - (www.opengl.org)
NeHe Tutorials - (nehe.gamedev.net)
Online Books - (Red Book) (Blue Book)
------------------------------Put THAT in your smoke and pipe it
Hey guys,
I''ve figured it out. Here''s what I''ve determined:

There''s a massive overhead when blitting. I can blit a full-screen image over 6 times before it starts to slow down. However, if I fill the screen with a bunch of 16*16 tiles, it slows down on the second pass.

This is convenient because my game is using massive BMPs... it is inconvenient because the particle engine will slow things down. :-(

Hope this information helps anyone planning on using SDL.

--Nairb
Questions:
1) What''s the amount of RAM on your video board ? 8MB looks like a minimum

2) Do you create a separate surface for each of the tiles , I mean is each tile a different bitmap or are you tiles located on a single bitmap file and when blitting you always use the same source surface ( the whole bitmap surface ) , just changing the source rectangle to select the exact tile you want to blit ?
The second method resulting in less overhead

May I recommend the book " Programming Linux games " from nostarch press. It has a nice part devoted to SDL.

Good luck

I have a 32mb TNT2, and I use one source bitmap. I was bliting 16x16 squares at 640x480.

This topic is closed to new replies.

Advertisement