Jump to content
  • Advertisement
Sign in to follow this  
SonicD007

SDL Game Engines

This topic is 3685 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

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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.

Thanks for replying.

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 this post


Link to post
Share on other sites
Quote:
Original post by SonicD007
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.


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 this post


Link to post
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 this post


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

SDL_Surface* Ball = LoadImage("Ball.bmp");

Correct?

Share this post


Link to post
Share on other sites
Quote:
Original post by SonicD007
oooooooooo!!! 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 this post


Link to post
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 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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!