Skip to main content
GameDev.net gamedev.net
🔒 Locked

SDL Game Programming in C

Started by KaanAlpar Jun 28, 2016 at 11:29 PM 24 replies 34.3k views
Original Post
KaanAlpar
KaanAlpar

Hello I am learning C and I want to make games in C with SDL. However I couldn't find any good resource for learning SDL in C except a handful of youtube tutorials. Any advice on how to use SDL with C?

ingframin
ingframin
I know what you mean. There is a c/SDL game programming tutorial on youtube.
But in any case it's not difficult to translate c++ tutorials to plain C.
It requires effort, mostly because you loose all the nice things of C++ (like classes or standard containers...).
I did the experiment though, I did not complete a full game but I can put my code on github if you wish to read it.
21st Century Moose
21st Century Moose

SDL is a C API so any SDL tutorial you find is going to be valid, at least so far as the SDL elements are concerned.

Maybe you need to improve your C a bit more first...

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
Kercyn
Kercyn

You may want to check out the FLARE engine. This is how I started with SDL a few years back. Not a tutorial per se, but it may help you understand some concepts or how you do certain things. I think it's in C++ but the concept is the same.

KaanAlpar
KaanAlpar

SDL is a C API so any SDL tutorial you find is going to be valid, at least so far as the SDL elements are concerned.

Maybe you need to improve your C a bit more first...

Yes, I am fairly new to C. I am trying to improve but my main goal is to make games so I just want to find places to learn when the time comes

KaanAlpar
KaanAlpar

I know what you mean. There is a c/SDL game programming tutorial on youtube.
But in any case it's not difficult to translate c++ tutorials to plain C.
It requires effort, mostly because you loose all the nice things of C++ (like classes or standard containers...).
I did the experiment though, I did not complete a full game but I can put my code on github if you wish to read it.

Yeah I am trying to translate some tutorials but I am not advanced in c or c++ so its hard. I'd love to read your code.

blabla3190
blabla3190

You may want to check out the FLARE engine. This is how I started with SDL a few years back. Not a tutorial per se, but it may help you understand some concepts or how you do certain things. I think it's in C++ but the concept is the same.

I will check it out thanks

KaanAlpar
KaanAlpar

They are either not in C or outdated

frob
frob
They are either not in C or outdated

The "not in C" part you'll have to cope with because of your choice to use C rather than C++.

The system by itself is C-based and all that knowledge can be directly used. Tutorials that use C++ stuff should be easily adjusted assuming you actually know C. Note that if you don't know how to program, picking a graphical game system like SDL is not the ideal place to learn the basics. If you don't already know how to program in the language you should start simple, with 'guess the number', 'tic tac toe', and other simple games instead of complex graphical games.

That out of the way, what specifically do you want to learn about SDL that is not addressed in the links or contents of their wiki (https://wiki.libsdl.org/Tutorials) or documentation?

KaanAlpar
KaanAlpar
They are either not in C or outdated

The "not in C" part you'll have to cope with because of your choice to use C rather than C++.

The system by itself is C-based and all that knowledge can be directly used. Tutorials that use C++ stuff should be easily adjusted assuming you actually know C. Note that if you don't know how to program, picking a graphical game system like SDL is not the ideal place to learn the basics. If you don't already know how to program in the language you should start simple, with 'guess the number', 'tic tac toe', and other simple games instead of complex graphical games.

That out of the way, what specifically do you want to learn about SDL that is not addressed in the links or contents of their wiki (https://wiki.libsdl.org/Tutorials) or documentation?

I know C, I am not a pro but I know the basics and I made some basic console games like pong and snake. Its just that every tutorial on the internet is using c++. Even the ones at https://wiki.libsdl.org/Tutorials . Sure I can try to transfer it to c++, but thats kind of a pain and I dont think I am that advanced yet. I was hoping to find a tutorial like lazyfoo but in C to learn the basics of how to make a game with SDL.

Kercyn
Kercyn

The way you use SDL does not differ from language to language. If you understand what's going on in a C++ tutorial, you can (usually trivially) write the same program in C (as far as SDL goes). Sure it'd be nice if you could find tutorials that are exactly what you need, but most of the time this won't be the case; you'll always have to change things.

Khatharr
Khatharr

Its just that every tutorial on the internet is using c++. Even the ones at https://wiki.libsdl.org/Tutorials.


Hint, hint...
void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.
Alternate-E
Alternate-E
They are either not in C or outdated

The "not in C" part you'll have to cope with because of your choice to use C rather than C++.

The system by itself is C-based and all that knowledge can be directly used. Tutorials that use C++ stuff should be easily adjusted assuming you actually know C. Note that if you don't know how to program, picking a graphical game system like SDL is not the ideal place to learn the basics. If you don't already know how to program in the language you should start simple, with 'guess the number', 'tic tac toe', and other simple games instead of complex graphical games.

That out of the way, what specifically do you want to learn about SDL that is not addressed in the links or contents of their wiki (https://wiki.libsdl.org/Tutorials) or documentation?

The way you use SDL does not differ from language to language. If you understand what's going on in a C++ tutorial, you can (usually trivially) write the same program in C (as far as SDL goes). Sure it'd be nice if you could find tutorials that are exactly what you need, but most of the time this won't be the case; you'll always have to change things.

One doesn't have pointers as a primary feature, the other does. Hell, both a programmer and a non-programmer can tell you that the syntax in even the classic "Hello World" example does not look the same. I like to use the example that saying "C/C++" in general is like saying "this tutorial is written in Spanish/Italian" while being written in just Spanish. Now imagine people just thought it was "your problem" that you only spoke Italian, really?

This debate has been bought up before and on multiple occasions otherwise. It's not much of a discussion since it's fairly obvious, the general consensus is that the two are - surprise - different and should be respected as such. So just because you can learn Portuguese if you know Spanish and vice-versa, doesn't mean you should have to, let alone want to.

See: A Raging C/C++ Debate on /r/Programming

Now to help out the OP, hint, go back in time. It's possible on the web, read and compile a bunch of those tutorials and go from there.

Editor // Joy-Toilet.com Anything But Shitty Entertainment!
21st Century Moose
21st Century Moose

One doesn't have pointers as a primary feature, the other does. Hell, both a programmer and a non-programmer can tell you that the syntax in even the classic "Hello World" example does not look the same. I like to use the example that saying "C/C++" in general is like saying "this tutorial is written in Spanish/Italian" while being written in just Spanish. Now imagine people just thought it was "your problem" that you only spoke Italian, really?


This is all well and good, but whether you like it or not SDL is still a C API. That means that it uses C datatypes (yes, even pointers) and C idioms, even in C++ and even if the rest of the C++ code is otherwise well-formed and idiomatic.

For sure a C++ SDL tutorial isn't going to give you code that you can just copy/paste to a C program, but I think we can all agree that copy/paste programming isn't learning. What it will give you is useful information like "this the API call I use to create a device" and "here are the flags I pass in to get the behaviour I need".

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
Queeninex
Queeninex

You can see youtube channels or C programming web sites.Good luck with.

hyyou
hyyou

Why did you decide to use C instead of C++?

(just want to know)

KaanAlpar
KaanAlpar

Why did you decide to use C instead of C++?

(just want to know)

Because I know C :D But I started learning c++ too.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.