Public Group

SDL Game Engines

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

Recommended Posts

I was looking on the gamedev wiki at engines and I was wondering if anyone knows of a very basic and easy to use SDL engine. I don't want it to have a mix of OpenGl and SDL or whatnot. Just pure SDL and C++. I don't care about 3D or networking capabilities. Just 2D graphics. Something that's very basic and good for beginner stuff. Thanks.

Share on other sites
I don't know how much of SDL you are familiar with, but it isn't too tough to work with without an engine. It is fairly basic and beginner friendly, especially if you follow tutorials like these. An existing engine using SDL would seem like overkill to me.

If you really do want an engine, I haven't seen one. Most 2D engines will use OpenGL or DirectX simply because they are more flexible. Why does it matter if the engine uses OpenGL (or DirectX, for that matter)? Typically an engine will hide all the API stuff from you anyway, so you won't even see much in the way of API code. Anything that runs SDL should also run OpenGL, so compatibility shouldn't be an issue.

Share on other sites
It is pretty simple, but I actually wanted the engine so I wouldn't have to always initialize and error check the surfaces. There is probably an easier way than what I was doing but it was just really repetitive and if I had a lot of surfaces, I can see how long and messy my code would get.

I was using a simple SDL game loop to make pong but I kinda gave up on it and went to other things and I was thinking of getting back to it now and redoing some of the code. I just figured a game engine would neaten things up.

(I had gotten up to the collision on the ball and paddle when I got tired of trying to get it to work. I had it working a little then changed the code then it stopped working and I was trying to learn swept collisions but I don't really have the patience to teach myself it :\)

Is there a simpler way to initialize and error check the surfaces? I'm thinking a function with a parameter that holds the surface name might work.

Oh and I didn't want DirectX or OpenGL with it because I don't know those Api's and I want to learn them eventually, but I wanted to learn SDL first because it is easier to follow.

Share on other sites
Quote:
 Original post by SonicD007Is there a simpler way to initialize and error check the surfaces? I'm thinking a function with a parameter that holds the surface name might work.

Why not make use of the OO paradigm?
class surface{    private:        SDL_Surface *_surface;    public:        surface();        ~surface();        bool valid() const { return _surface; }        // possibly override operator bool        operator bool() const { return valid(); }        // allows stuff like        // if (surface) doStuff(surface);                void fromFile(const std::string &fileName)        {            /* do loading from file */;            if (!_surface)                throw std::runtime_error("could not load surface from " + fileName");        }        void blit(const SDL_Rect &p, const surface &other)        {            // blit surfaces        }};

Obviously that's an extremely over-simplified example, but it'll make things a lot easier.

Share on other sites
It's not that hard to just write wrappers around SDL_LoadBMP and friends. A lot of tutorials tell you to do this:
SDL_Surface* LoadImage(char* filename){    SDL_Surface* temp = SDL_LoadBMP(filename);    if(!temp){        //error handling, probably throw out"    }    SDL_Surface* final = SDL_DisplayFormat(temp);//converts image to display format, for efficiency    SDL_FreeSurface(temp);    return final;}

That and a few other functions are all the "Engine" you need. Maybe a wrapper for blitting, that does checking.

P.S.: There's a two cent royalty every time you call that function [grin]

Share on other sites
oooooooooo!!! I understand now. And then to use that function I would just do something like

Correct?

Share on other sites
Quote:
 Original post by SonicD007oooooooooo!!! I understand now. And then to use that function I would just do something like SDL_Surface* Ball = LoadImage("Ball.bmp");Correct?

Exactly.

If you haven't seen the the tutorials at Lazy Foo they could be helpful for you with learning SDL. That function is basically the same as the LoadImage function in those tutorials.

Share on other sites
I worked on creating a base for any SDL games (a sort of engine really) for my computer class in school. My teacher never programmed graphically before, so I was given the assignment to create something that the class could use to program graphically without having to cope with all the issues of initializing and such.

Maybe it can be of interest to you. The coding habits arent the best, I learned a lot since I wrote this, but it should be enough to get you going. Feel free to modify it as you please: Linky

P.S.
esk is an acronym fo European School Karlsruhe, the school I finished this year (going to uni next year).

Share on other sites
Well then,

Kyra Sprite Engine

looks kicking cool and is exactly what you want, although I prefer to write my own.

Good luck,
Frederick

1. 1
2. 2
3. 3
4. 4
Rutin
16
5. 5

• 12
• 9
• 12
• 37
• 12
• Forum Statistics

• Total Topics
631415
• Total Posts
2999965
×