Jump to content
  • Advertisement
Sign in to follow this  
Tanay Karnik

Learning SDL For Game Development

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

Hello!

 

I am new to Game Development and started with SDL and C++. Well I'm a bit confused with learning SDL.

I know that great tutorials are available at http://lazyfoo.net

But using those I'll learn about using SDL and its features. How do I understand implementing SDL in game development. Of Course I could try to figure out it on my own. But then how I will understand the best practices.

 

I even got the book SDL Game Development after reaching till page 65 and so... I thought that the author is going about things pretty much his way. So I might feel boring at some times and get interested in some further things (I suppose it isn't my way of learning).

 

So what do I do?

Should I follow the tutorials at lazyfoo.net and then come back and focus on game development ( if yes, how? ) or is there any better resource which will guide me to both simultaneously. I have already learned a few things about SDL and hence made up my mind to start with it for game development there (so no changing minds there).

 

In short, I want to learn to things the SDL library and game development ( along with the best practices and tricks, etc ). So which of them should I learn first or both simultaneously. And what resources do you suggest?

Share this post


Link to post
Share on other sites
Advertisement

SDL is just the library talking to your OS for video/mouse/keyboard/sound, nothing more. It's not a complicated library to use.

The far bigger part of the challenge is making a game.

 

On the other hand, you do need SDL, or you cannot show anything, or ask about the position of the mouse cursor, mouse clicks, and so on.

 

My strategy would be to make yourself a basic program that can open a window and talk with the OS about mouse and keys, and then switch to game development.

Extend the SDL interface as needed.

 

I would suggest you start with SDL, and learn about starting and shutting down an SDL application. You also need a window. Together this is mostly a "hello world" SDL program, of about 1 main function.

 

Next thing you need is input from the mouse, or keyboard. Find a tutorial to read mouse positions, and one to detect mouse button clicks.

Just a printf("You clicked the %d button at (%d,%d)\n", ...); type of output is sufficient.

 

For bonus, add a key press/release detection too. I always make the 'q' key quit the program, very useful during development :)

 

 

This is mostly the basic setup for a game. Now you can start programming your game around this code.

 

 

A few notes:

1. You may want to browse the SDL tutorial or book at some point, so you get a vague idea of what's there. You don't have to understand how they do it, or actually read the tutorial, just the aim of the lessons is sufficient. The whole idea is that somewhere in the back of your mind, you then know "timers", "frame rates", and so on. When you run into a problem with your game, chances are that your mind will connect that background information with your problem at an unexpected moment, which may give you that eureka moment.

 

2. I don't know how much C++ you know. If you are new, C++ is a complicated beast, it is not a language aimed at new users, so you will have a hard time getting to grips with programming. For faster learning/progress, I would recommend Python. It's a higher level language, very well designed, and with a big community. It has SDL support, in the form of pygame. You will encounter pretty much all issues that you would encounter with C++ too, except Python is simpler to modify/fix, and encourages experimenting. When you are a bit accustomed to programming, you can learn C++, and copy most things you learned in Python to C++.

 

3. If you're looking for how to start programming a game, read http://www.gamedev.net/page/resources/_/technical/game-programming/your-first-step-to-game-development-starts-here-r2976

 

Good luck, and if you have further questions, just ask :)

Share this post


Link to post
Share on other sites

Personally I'm a huge fan of SDL, but it's not a game engine, it's just an OS abstraction. If you've never made a game before, you will probably spend a lot of time trying to implement a game engine on top of it. To me, the game engine is most of the fun of programming a game, but some people find it tedious and there is still a pretty high learning curve. You would save a lot of time and hassle using a fully-featured game engine; but if you want to learn how to do all that yourself, don't let me deter you. :)

If you're using SDL's render API, let SDL choose the renderer for you. It generally chooses the one that will perform the best, so there's not many good reasons not to.

SDL is very simple to use and LazyFoo's tutorials are very good. I highly recommend you stick to them. If you have any specific questions, ask away, but there's not much more general help that can be given.

Share this post


Link to post
Share on other sites

Hello!

 

I am new to Game Development and started with SDL and C++. Well I'm a bit confused with learning SDL.

I know that great tutorials are available at http://lazyfoo.net

But using those I'll learn about using SDL and its features. How do I understand implementing SDL in game development. Of Course I could try to figure out it on my own. But then how I will understand the best practices.

 

I even got the book SDL Game Development after reaching till page 65 and so... I thought that the author is going about things pretty much his way. So I might feel boring at some times and get interested in some further things (I suppose it isn't my way of learning).

 

So what do I do?

Should I follow the tutorials at lazyfoo.net and then come back and focus on game development ( if yes, how? ) or is there any better resource which will guide me to both simultaneously. I have already learned a few things about SDL and hence made up my mind to start with it for game development there (so no changing minds there).

 

In short, I want to learn to things the SDL library and game development ( along with the best practices and tricks, etc ). So which of them should I learn first or both simultaneously. And what resources do you suggest?

 

I worked through Lazy Foo's tutorials, and found them to be a really good introduction to SDL. After I was done with them, I bought that book; I read most of it, and found it to have issues. I don't know if there are other books about SDL 2.

 

I suggest you try SFML. It is simpe, clean, well-documented, and has several books written about it. I bought all of those books, and the one I like best is SFML Game Development: not only it introduces SFML, but also does a good job of introducing architecture concepts. After I was done with it, Game Programming Patterns made a lot more sense.

Share this post


Link to post
Share on other sites

SDL is just the library talking to your OS for video/mouse/keyboard/sound, nothing more. It's not a complicated library to use.

The far bigger part of the challenge is making a game.

 

On the other hand, you do need SDL, or you cannot show anything, or ask about the position of the mouse cursor, mouse clicks, and so on.

 

My strategy would be to make yourself a basic program that can open a window and talk with the OS about mouse and keys, and then switch to game development.

Extend the SDL interface as needed.

 

I would suggest you start with SDL, and learn about starting and shutting down an SDL application. You also need a window. Together this is mostly a "hello world" SDL program, of about 1 main function.

 

Next thing you need is input from the mouse, or keyboard. Find a tutorial to read mouse positions, and one to detect mouse button clicks.

Just a printf("You clicked the %d button at (%d,%d)\n", ...); type of output is sufficient.

 

For bonus, add a key press/release detection too. I always make the 'q' key quit the program, very useful during development smile.png

 

 

This is mostly the basic setup for a game. Now you can start programming your game around this code.

 

 

A few notes:

1. You may want to browse the SDL tutorial or book at some point, so you get a vague idea of what's there. You don't have to understand how they do it, or actually read the tutorial, just the aim of the lessons is sufficient. The whole idea is that somewhere in the back of your mind, you then know "timers", "frame rates", and so on. When you run into a problem with your game, chances are that your mind will connect that background information with your problem at an unexpected moment, which may give you that eureka moment.

 

2. I don't know how much C++ you know. If you are new, C++ is a complicated beast, it is not a language aimed at new users, so you will have a hard time getting to grips with programming. For faster learning/progress, I would recommend Python. It's a higher level language, very well designed, and with a big community. It has SDL support, in the form of pygame. You will encounter pretty much all issues that you would encounter with C++ too, except Python is simpler to modify/fix, and encourages experimenting. When you are a bit accustomed to programming, you can learn C++, and copy most things you learned in Python to C++.

 

3. If you're looking for how to start programming a game, read http://www.gamedev.net/page/resources/_/technical/game-programming/your-first-step-to-game-development-starts-here-r2976

 

Good luck, and if you have further questions, just ask smile.png

 


I understand and agree with your approach. First learning to do the simple things with the library and then heading for game development. But the good thing is that I already know about quit events, keyboard press/release events. I'll just have to check out the mouse events ( I was going to, but stopped and asked this question! ) Thank You for your quick answer I'll go with it. And since I am already familiar with C++, and as I mentioned in my original thread I'm going to stick with SDL and C++.

 

Even thanks for the awesome resource, I currently have it open in another tab and am goin' to read it first.

Share this post


Link to post
Share on other sites

Personally I'm a huge fan of SDL, but it's not a game engine, it's just an OS abstraction. If you've never made a game before, you will probably spend a lot of time trying to implement a game engine on top of it. To me, the game engine is most of the fun of programming a game, but some people find it tedious and there is still a pretty high learning curve. You would save a lot of time and hassle using a fully-featured game engine; but if you want to learn how to do all that yourself, don't let me deter you. smile.png

If you're using SDL's render API, let SDL choose the renderer for you. It generally chooses the one that will perform the best, so there's not many good reasons not to.

SDL is very simple to use and LazyFoo's tutorials are very good. I highly recommend you stick to them. If you have any specific questions, ask away, but there's not much more general help that can be given.

 

 

 

Hello!

 

I am new to Game Development and started with SDL and C++. Well I'm a bit confused with learning SDL.

I know that great tutorials are available at http://lazyfoo.net

But using those I'll learn about using SDL and its features. How do I understand implementing SDL in game development. Of Course I could try to figure out it on my own. But then how I will understand the best practices.

 

I even got the book SDL Game Development after reaching till page 65 and so... I thought that the author is going about things pretty much his way. So I might feel boring at some times and get interested in some further things (I suppose it isn't my way of learning).

 

So what do I do?

Should I follow the tutorials at lazyfoo.net and then come back and focus on game development ( if yes, how? ) or is there any better resource which will guide me to both simultaneously. I have already learned a few things about SDL and hence made up my mind to start with it for game development there (so no changing minds there).

 

In short, I want to learn to things the SDL library and game development ( along with the best practices and tricks, etc ). So which of them should I learn first or both simultaneously. And what resources do you suggest?

 

I worked through Lazy Foo's tutorials, and found them to be a really good introduction to SDL. After I was done with them, I bought that book; I read most of it, and found it to have issues. I don't know if there are other books about SDL 2.

 

I suggest you try SFML. It is simpe, clean, well-documented, and has several books written about it. I bought all of those books, and the one I like best is SFML Game Development: not only it introduces SFML, but also does a good job of introducing architecture concepts. After I was done with it, Game Programming Patterns made a lot more sense.

 

 

I think I agree with LazyFoo's tutorials being good. I think with my experience with SDL Game Development book, I'm going to stay away from books as a beginner because they take away your fun of doing things yourself and guide you throughout. Also, while choosing between the libraries (SDL, SFML, Allegro, etc.) I considered each of them very well and went with SDL for starting. I will try the others afterwards.

Share this post


Link to post
Share on other sites

Just out of curiosity, why did you choose SDL over SFML?

 

SFML is more high level, right? Its object oriented, right? And hence more easier to learn, right?

 

Well since SDL is more low level, written in c, more difficult to learn, I chose SDL. I thought that I would learn more 'game development' if I start from more low level. I even heard that SDL is more fast (since its written in c, correct me if I'm wrong) Who says I won't learn SFML? After learning SDL, I can learn SFML just by going through the documentation, examples, etc.

 

Also, since SFML is written in c++ and they have their own objects and such stuff, (my personal opinion) learning it first will result in learning (too) library specific things.

( I know some things about SFML since my brother who is also doing game develoment is learning SFML first. )

Share this post


Link to post
Share on other sites


Well since SDL is more low level, written in c, more difficult to learn, I chose SDL.

I've used both SDL and SFML. I learned SDL first. SDL is simpler to use, to me, than SFML.


I thought that I would learn more 'game development' if I start from more low level.

SDL isn't that low-level. It's fundamentally an abstraction of abstractions. It's actually higher level in some ways than SFML, but it lets you write lower level code. This is my personal reason for preferring SDL over SFML.
You should play around with SDL_Surface sometime. This is where the low-level opportunities really come up. :)


Also, since SFML is written in c++ and they have their own objects and such stuff, (my personal opinion) learning it first will result in learning (too) library specific things.

SFML is a much larger library than SDL. And its interface requires learning several interfaces just to start rendering graphics. I definitely agree with you here.

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!