Advertisement

Fastest way for 2D animation with SDL

Started by October 12, 2001 07:59 PM
3 comments, last by Biased turkey 22 years, 11 months ago
If I want to do 2D animation with an object that has 4 different positions is it better to: 1) Create 4 diffrent bitmaps , load each in a separate SDL surface and blit the whole surface of the selected sprite on the background 2) Create 1 single bitmap with the 4 sprites , load it in 1 single SDL surface and when blitting changing the source rectangle to select the specific sprite out of the 4 I want to draw on the background. Or it doesn''n matter, both methods have more or less the same speed Thanks in advance for any advice or opinion.
I don''t personally know which is better (it''s been a long time since I have done pure 2D graphics, although it doesn''t matter much: in OpenGL using a since texture is faster). Why don''t you set up a simple benchmark?

Test 1: Load 4 64x64 images, and blit them 100+ times, get the time it took to do.
Test 2: Load 1 256x256 image, and blit each quadrant 100+ times, get the time it took to do.

[Resist Windows XP''s Invasive Production Activation Technology!]
Advertisement
I haven''t done a test on your particular situation, however:

1) SDL builds a "blit map" with function pointers for blitting from one surface to another. If you switch surfaces all the time, this blit map needs to be rebuilt all the time, so a single surface seems to be better.

2) With a single surface, you get less overhead. For every surface, a structure with width/height components as well as a pixelformat structure is allocated.

Apart from that, the performance will also depend on the back-end used, but in general there''s no reason why using one big surface should ever be slower than using several smaller surfaces (unless the big surface is so big that it can''t be stored in video memory or something...).

cu,
Prefect

One line of sourcecode says more than a thousand words.
Widelands - laid back, free software strategy
I''m going to vote for the big image method.. and here''s why:

Using SDL with your sprites, you most likely would use a colorkey to do transparency, then slide it through the DisplayFormat (to ready it..)

The reason I''d recommend this way and would think this would be faster is because you save reduce the number of structures used to take care of your surfaces.

Imagine it on a larger scale.. if you had a ten frame walk cycle. Now instead of , say.. 50*500 (for a 50x50 tile) , you''d have ten 50x50 tiles. You''d have to set ten colorkeys, handle ten surfaces. If it all uses the same information, anything else has to be a waste.

Magnwa
First I want thank all the people who took some of their time to reply my post.That forum for sure has some very knowledgeable and helpful experts.
I''m now convinced that a big surface with the 4 sprites is the best way to go.Magnwa is right , I''ll use a colorkey to do transparency and slide it through the SDL_DisplayFormat method.

Good idea from Null and Void too: This could be an interesting project to run benchmarks comparing the 2 ways of blitting, this should give the final aswer about the question.

I asked the question in the first place because in his book " Tricks of the Windows programming gurus " André Lamothe creates 1 surface for every frame, while John R. Hall in " Programming Linux games " uses 1 surface while changing the source rectangle. As both of these guys really know their business I couldn''t make up my mind. Of course Direct X might have a completely different internal scheme for blitting.

So, thanks one more time.

P.S. my next question will be about some apparent missing OpenGL headers while trying to integrate OpenGL ( or Mesa in my case ) with SDL. But as today is Sunday, I ''ll give you a well deserved break

This topic is closed to new replies.

Advertisement