Jump to content
  • Advertisement
Sign in to follow this  

Is SDL too slow for tile-based games?

This topic is 4342 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, first let me say that I'm NOT trying to start a flame war here, as every other topic I've seen on similar issues seems to devolve into. I apologize if this becomes one. I've been looking around at other topics, the internets, etc., and I get the overall impression that (I'm probably pretty worong here), to do fast 2D, and do it well, you need tgo use a 3D rendering engine (which doesn't make too much sense to me since the Super Nintendo was doing fast 2D/tile-based, so why a 2 GhZ computer with a gig of ram can't is beyond me...). But I see topic after topic here compliaing about how SDL is "slow", and the inevitible next response is "Use (OpenGL/DirectX)". I really, really don't want to go the 3D route, I've had enough trouble with those sorts of things already, and I gather to get 2D working well in a 3D engine, you need all sorts of batching and optimization. This would probably be a good learning experience, but for this proect I want to concentrate more on the AI and other things than the graphics. Additionally, if there are any high-level features I need in OpenGL (such as a particle system, etc.), I should be able to access them fine from SDL, right? If I REALLY must do 3D, I will, but I'm hoping I don't have to. So, my big questions are... 1. Is SDL too slow to work with, specifically for a tile-based game? 2. I gather SDL doesn't support rotation. Does this mean that I'll have to have hundreds of different images, one for every sprite in every possible orientation? 3. Are there any other features I need I'll be sacrificing by chosing SDL (for example, I read SDL doesn't support non-alpha blending... I can't see what other forms of blending I'd need, but can an experienced game designer please warn me if there are any)? 4. Are there any other 2D libraries I could look into that might be faster or more fully-featured than SDL? Note that I'm not really looking for a game library (i.e. Allegro) per se, I'd like to have to figure a lot of things out for myself. I wouldn't be against chosing one if that would really help me out, but I don't want to be locked into certain programming paradigms or given hundreds of features I won't use (for example, I don't need any copllision detection in this game; it's a turn-based strategy). 5. Do you have any suggestions of ways to optimize SDL that I should keep in mind from the beginning (i.e. I was thinking I should redraw every frame from scratch, is this a bad idea?). Thanks for reading! Best of wishes, xycos

Share this post


Link to post
Share on other sites
Advertisement
I can't tell you whether SDL is too slow for your purposes, but I'll make a couple of other observations.

AFAIK SDL doesn't handle image rotation, so this could be a drawback of the SDL-only approach if you need this feature.

As for using a 3D API, no, batching and other similar optimizations probably would not be necessary for a 2D game; unless you're doing something really fancy, the raw power of the hardware should be more than enough to handle a tile-based game. Heck, you could probably even get away with using OpenGL immediate mode if you wanted.

Using a 3D API such as OpenGL in conjunction with SDL will give you the best of both worlds; the ease of use and portability of SDL (which will take care of many platform-specific tasks for you) plus the speed and feature set of hardware rendering.

If you go with OpenGL, it's not at all hard to get going if you use SDL along with it. Personally, I'd recommend SDL + OpenGL, even for 2D games. Using OpenGL will give you many extra features 'for free', plus sufficient rendering power that you won't have to worry about performance issues.

The only caveat would be dealing with any quirks related to OpenGL on Windows. I'm developing in OS X currently so can't comment on that, but I'm sure someone else can.

Share this post


Link to post
Share on other sites
Hey, I'm not that much of a graphics programmer, but here's my 2 cents.

If you check out the games section on www.libsdl.org, you'll find out that tons of games use it. They might be using OpenGL too, but I'm pretty sure a decent amount doesnt.

Also, what kind of rotations are you looking for? if its simple flips, if SDL doesn't support it itself, I guess it would be pretty easy for you to create a new SDL_Surface and copy the image upside down or from right to left...

Something that's costy with 2D graphics, is alpha blending. If you can get away with alpha MASKING, you'll get _WAY_ faster results.

Also, think of using a dirty rects method when rendering your scene. It makes no sense to update the entire scene if only a few characters moved.

If you're doing this project to mess around with AI, I'm pretty sure SDL only will do the job...

As for the Nintendo thing, keep in mind that consoles are pieces of hardware specialized in rendering games, its not the same thing as a PC. As for the use OpenGL / DirectX, its pretty cheap to do alpha blending on the GPU and to rotate textured quads with filtering... something that would take precious time on the CPU if done in 2D.

Hope this helps

Share this post


Link to post
Share on other sites
1) I'm using SDL in combination with OpenGL for the graphics. Those graphics are really fast. SDL itself is also pretty fast(the Windows port at least, I don't know of any others).
The problem is that surface manipulation like stretching is slow when you use the SDL graphics calls instead of OpenGL. That's why you can use the "sdl_gfx" library from http://www.ferzkopp.net/Software/SDL_gfx-2.0/ ór you can just use OpenGL of course.

2) Use the graphics lib above to get zoom and rotation options. You don't need it if you want to use OpenGL.

3) No clue.

4) Allegro is pretty well-known:
http://www.talula.demon.co.uk/allegro/
But my favorite is still SDL :)

5) Not really, SDL is pretty straight-forward. Make sure you look at the samples on the libsdl.org homepage:
http://www.libsdl.org/demos.php
http://www.libsdl.org/applications.php

[edit] sorry for any double info

Share this post


Link to post
Share on other sites
Can't really help you much but if SDL was too slow to work with i'm sure they wouldn't make larger projects in this API. If I remember right, some people or even companies make games in SDL that is platform independent. I saw a website with games made in SDL that was really impressive.

SDL doesn't support rotation but the library SDL_gfx makes it possible. I haven't tried SDL_gfx and i've heard it's not a good idea to use rotation in SDL.

The question is why they would make a slow API? The fact that thousands of people uses SDL should be proof enough that it's not slow.

Share this post


Link to post
Share on other sites
Quote:
Original post by xycos
1. Is SDL too slow to work with, specifically for a tile-based game?


No, if programmed correctly SDL will be plenty fast for a tile based game.

Quote:

2. I gather SDL doesn't support rotation. Does this mean that I'll have to have hundreds of different images, one for every sprite in every possible orientation?


There are libraries that can do this for you, but it will be done in software, making it a slow.

Quote:

3. Are there any other features I need I'll be sacrificing by chosing SDL (for example, I read SDL doesn't support non-alpha blending... I can't see what other forms of blending I'd need, but can an experienced game designer please warn me if there are any)?


SDL does alpha blending in software, so this can be slow. Keep in mind, this does not mean that if your sprites have a color key, that will be slow. The rest of your question depends on what features your game needs.

Quote:

4. Are there any other 2D libraries I could look into that might be faster or more fully-featured than SDL? Note that I'm not really looking for a game library (i.e. Allegro) per se, I'd like to have to figure a lot of things out for myself. I wouldn't be against chosing one if that would really help me out, but I don't want to be locked into certain programming paradigms or given hundreds of features I won't use (for example, I don't need any copllision detection in this game; it's a turn-based strategy).


Now, this is just my opinion, but SDL is the best I have ever found.

Quote:

5. Do you have any suggestions of ways to optimize SDL that I should keep in mind from the beginning (i.e. I was thinking I should redraw every frame from scratch, is this a bad idea?).


SDL itself doesn't need any optimization. However, you need to make sure you are following some guidelines to make SDL as fast as it can be. First, Blitting from a software surface to a hardware surface will be slow. It is best when you load images to blit them to a created hardware surface during the load, and then use that surface to blit to the back buffer. Along those lines, make sure all your hardware surfaces are the same format as the back buffer. Also, if you don't need to blit the whole image, than don't. Those tips will keep your SDL blits as fast as they can be. Other than that, the only optimizations you need to worry about are the ones for your specific game.

Also, keep in mind, even though, rotating, zooming and alpha blending an image is slow in software, it is only slow relatively to how fast it can be done in hardware with a 3D api. If you are smart about what you are doing, you can do a tile based game in SDL that will run fast enough.

Share this post


Link to post
Share on other sites
Thank you, all.

How difficult is it to combine OpenGL and SDL, and what would I use each one for? For example, would I use SDL to draw the background layer of the map, and OpenGL to draw character sprites on top of that? Would I use OpenGL to make tiles/background? etc.

Thank you,
Best of wishes,
xycos

Share this post


Link to post
Share on other sites
If you use SDL to use OpenGL, you have to draw everything using OpenGL. SDL supports a mixed mode, but I personally have never gotten to work to any success, and consider it bad form.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!