Writing 2D Games in C using SDL by Thomas Lively

  Рет қаралды 190,872

CS50

CS50

Күн бұрын

Пікірлер: 155
@hsinhunglin9108
@hsinhunglin9108 5 жыл бұрын
Most SDL demo video I find on the youtube is C++ in Windows, and thank you for making a demo in C and Linux.
@haseldanprince9658
@haseldanprince9658 4 жыл бұрын
@PussyIsHere Hey now, we all have our perks and cons. Try coding with OOP in C.
@hugo-garcia
@hugo-garcia 3 жыл бұрын
@Zed hahahaha
@m3hdim3hdi
@m3hdim3hdi 3 жыл бұрын
“The problem with object-oriented languages is they’ve got all this implicit environment that they carry around with them. You wanted a banana but what you got was a gorilla holding the banana and the entire jungle.” - Joe Armstrong
@s7v7n97
@s7v7n97 2 жыл бұрын
@@m3hdim3hdi WTF LOL
@dancom6030
@dancom6030 Жыл бұрын
@@haseldanprince9658 object orientation is pretty easy to emulate in C when it is necessary.
@reconmaster907
@reconmaster907 3 ай бұрын
There are nearly no competent sdl c teachers on youtube. This is the only sdl c tutorial i found which actually helped me build something useful and become familiar with the library and documentation. Thanks.
@notdeus3834
@notdeus3834 2 ай бұрын
The average SDL Tuber: Hi guys.... waffling waffling afflin... 40 mins later, so yeah, that's how you draw a triangle
@PatrioticGestalt
@PatrioticGestalt 3 жыл бұрын
5 years later, still useful. Thumbs up.
@qwerty273
@qwerty273 3 жыл бұрын
By far the best video I’ve watched so far on SDL with C. Quick, and easy.
@harriscrews1282
@harriscrews1282 4 жыл бұрын
If you're on macOS and your window doesn't seem to be popping up (as it was not for me), it's because you need to poll for events. It seems that on the creation of the window there are a few events that are queued before the window appear event. So try something like this: SDL_Event event; bool isRunning = true; while (isRunning) { while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { isRunning = false; } } } instead of using the delay method. Hope this helps!
@joshli5309
@joshli5309 7 жыл бұрын
This has rendered great help and allowed me to surface above a lot of troubles, thank you. Deserves better applause at the end.
@thomaslively8177
@thomaslively8177 7 жыл бұрын
Hi Josh, I'm glad you found the seminar helpful! Good luck in your projects :)
@a.v7998
@a.v7998 8 ай бұрын
Loved it man. This is the best SDL tutorial with C language!
@NeilRoy
@NeilRoy 8 жыл бұрын
Note: If you stick in a *default:* for the switch statements, that will get rid of the warnings. If you wanted, you could put some code in the default to output the key that was pressed to the console for debugging. To compile this for Windows I recommend Code::Blocks which comes with MinGW, or grab MinGW and Notepad++ which will colourize the text like gedit and you can compile as he does in a console. Personally I prefer Code::Blocks as you can also download it for Linux which makes it VERY nice for cross platform stuff. It fits perfectly with SDL. The only differences with compiling this with Windows is you have to create your main function like: int main(int argc, char *argv[]) { and you have to link in SDL2main BEFORE you link in anything else -lSDL2main -lSDL2 -lSDL2_Image Otherwise, everything else works as expected.
@w花b
@w花b 2 жыл бұрын
Thanks, I'm in the exact same situation and was tired of making ASCII graphics for my game.
@vaslot
@vaslot 6 жыл бұрын
Awesome presentation! I am new to SDL 2 programming and loved it. Thank you!
@yusufmalikul
@yusufmalikul 2 жыл бұрын
As of today (2022) your code still works, and I use a mac. Thanks!
@nyume815
@nyume815 6 жыл бұрын
So I'm planning to make a small platformer for my Data Structure class, this tutorial helped me A LOT to understand and begin the development. Next step, reading the documentation!
@_trion
@_trion 8 жыл бұрын
Awesome introduction to sdl and great teacher, made it easy to understand :-)
@juanpisani9297
@juanpisani9297 7 жыл бұрын
Awesome CRAP... Where is the CODE ?????????????????????????????????? Were you able to get it ???????????????????????????????????????????????????????????????????????/ Awesome
@vncsdev
@vncsdev 7 жыл бұрын
github.com/tlively/sdl_seminar/ he told us where to get the code during the first 5 minutes of the video...
@jonathanmoore5619
@jonathanmoore5619 3 жыл бұрын
@@juanpisani9297 coding is "not for you", Jen...
@michaelwoodruff5752
@michaelwoodruff5752 7 жыл бұрын
Hey thanks guy. I've been using lazy foo's tutorial to get farmiliar with sdl, but I think I'll start using the wiki now.
@karimkohel3240
@karimkohel3240 5 жыл бұрын
cs5 does it again. thank you guys so much for everything
@UnifyRadar
@UnifyRadar 10 күн бұрын
If you use GCC and not Clang, your console will be filled from top to bottom with warnings about unhandled key codes, easiest way to get rid of those warnings is to add a default case to your switch statement that just says default: break; Remember to do this for both the SDL_KEY_DOWN and SDL_KEY_UP switches.
@atiedebee1020
@atiedebee1020 3 жыл бұрын
This tutorial was great, thank you for this!
@ГерриПитт
@ГерриПитт 4 жыл бұрын
Thanks, man! Really really helpful introduction to SDL!
@electricimpulsetoprogramming
@electricimpulsetoprogramming 2 жыл бұрын
this guy explains very good
@FernandoBasso
@FernandoBasso 8 жыл бұрын
Wow! This lesson is overwhelmingly informative. Thanks a lot! Superb work!!!
@lev4392
@lev4392 3 жыл бұрын
Super, super helpful! Thank you so much!
@syedbaryalay5849
@syedbaryalay5849 5 жыл бұрын
great presentation mate, nice intro this crazy hell
@beb9632
@beb9632 3 жыл бұрын
Me: Im gonna write a game with SDL! Segmentation fault (core dumped): Hello
@abhilashsinha115
@abhilashsinha115 3 жыл бұрын
That's exactly the perfect way to get started, cheers mate!!
@not_herobrine3752
@not_herobrine3752 2 жыл бұрын
its been seven months, any further progress?
@altaghyeer
@altaghyeer 3 жыл бұрын
very good presentation thank you very much
@AikHuMuslim
@AikHuMuslim 2 жыл бұрын
Thanks for the great content for the c language
@alaindevtecchannel2232
@alaindevtecchannel2232 3 жыл бұрын
This video is quite fantastic, but I'm actually lost on the hello4 and 5 files ... Especially concerning the x and y positions, as long as I'm a beginner in SDL.
@kevinnudel9682
@kevinnudel9682 2 ай бұрын
Thank you.
@evildiesel1709
@evildiesel1709 7 жыл бұрын
Excellent tutorial! Gonna give it a bash now:)
@gabrielbap1
@gabrielbap1 3 жыл бұрын
Great class!
@abraham4374
@abraham4374 6 жыл бұрын
Loved this video
@chronicsnail6675
@chronicsnail6675 4 жыл бұрын
You are the best thanks alot !
@yashwanthcb
@yashwanthcb 8 жыл бұрын
I would feel happy if cs50 provides a tutorial on openGL/c++
@kopuz.co.uk.
@kopuz.co.uk. 6 жыл бұрын
get a book.
@aidensmith6277
@aidensmith6277 6 жыл бұрын
@@kopuz.co.uk. we got a negative nancy here xd
@kopuz.co.uk.
@kopuz.co.uk. 6 жыл бұрын
@@aidensmith6277 because books are negative?
@aidensmith6277
@aidensmith6277 6 жыл бұрын
@@kopuz.co.uk. no, just the very abrupt reply was a bit... abrupt? Hahaha
@kopuz.co.uk.
@kopuz.co.uk. 6 жыл бұрын
@@aidensmith6277 No!
@RJPG_7
@RJPG_7 3 ай бұрын
Can i do that in termux?
@LisandroLorea
@LisandroLorea 3 жыл бұрын
Why is SDL_PollEvent void? I mean I guess it could also be defined so that you do SDL_Event event = SDL_PollEvent(). I don't have much experience with C. Is it just a convention or is there any advantage in asking for pointers to fill with return values over just returning the values?
@slowbro13215
@slowbro13215 3 жыл бұрын
One reason is that it can have more than 1 return value, which is normally impossible in C. SDL_PollEvent also returns an int that tells whether there is another pending event. Sometimes passing by reference instead of value can save memory, depending on the size of the data structure of course. In the case of SDL_PollEvent I would guess it is just to have more than 1 return value. Someone else can correct me if I'm wrong here, I'm still a beginner!
@salimtrabelsi2163
@salimtrabelsi2163 5 жыл бұрын
thanks man its really helpful 😍❤❤
@katiacor
@katiacor 2 жыл бұрын
Hi! I hope you can help me with this. I have Linux running on a virtual machine (VirtualBox + Vagrant), and I use VS Code for access to the Shell and compile from there with the gcc. I just compiled my first SDL2 mini program that should just prompt a window for 2 seconds, however, nothing is showing up. I had no issues at compilation, but nothing pops up when I run the executable (./main). I know the program had no issues cause it returned 0 by the end, and I cannot input anything for those 2 seconds. So I was wondering what is missing in my set up so I can see the window from my program. I apologize if I'm not clear enough, but I only learnt programming in C 3 months ago. Thanks!
@rambabuupreti5669
@rambabuupreti5669 6 жыл бұрын
I am bachelor 1st year student and i wanna learn c to the fullest Idk the codes how can i learn the graphics code and other code. Is there any book.? Please help me anyone😕
@stefanluginger3682
@stefanluginger3682 6 жыл бұрын
Rambabu Upreti good idea. I want that, too. I had some C++ in university but C ist still more used and has a lot of interesting use cases C++ does not
@ChristianTheChicken
@ChristianTheChicken 3 жыл бұрын
The C Programming Language by Brian Kernighan and Dennis Ritchie.
@GCKteamKrispy
@GCKteamKrispy 6 ай бұрын
CS50 please make this course for 3D in GD50
@PaketNAParkete
@PaketNAParkete 6 жыл бұрын
Спасибо большое за видео! мы изучаем эту библиотеку в университете, но преподаватели не очень хорошо нам её объясняют. Мы даже не догадывались, что есть официальный сайт с подробным описанием каждой функции.
@TheUltimateLizard
@TheUltimateLizard 6 жыл бұрын
Что за университет и что за факультет?
@RedQueenOfficial
@RedQueenOfficial 7 жыл бұрын
Awesome
@openmarkand
@openmarkand 4 жыл бұрын
SDL include convention is SDL.h only though.
@chesterhackenbush
@chesterhackenbush 7 жыл бұрын
Excellent!
@primalaspid7197
@primalaspid7197 4 жыл бұрын
Very interresting
@dashl5069
@dashl5069 5 жыл бұрын
When I run this it just says not responding and the window never appears, there is no error though, and it waits 5 seconds and then quits. (I am on mac)
@bigboysteen7638
@bigboysteen7638 5 жыл бұрын
make you sure you downloaded and inclused the SDL2 image library, it isn't mentionned here but it is necessary in order to run the program also don't forget to copy the SDL2 dll's in your project's folder
@marcelinoborges5088
@marcelinoborges5088 6 жыл бұрын
Don't we have cs50 appliance available to download anymore??
@thomaslively8177
@thomaslively8177 6 жыл бұрын
This should work with almost no modification on a linux distro like Ubuntu as well.
@openmarkand
@openmarkand 4 жыл бұрын
Please note that your makefile is not portable as it requires GNU make. Also the include convention is SDL.h not SDL/SDL.h.
@krystof7059
@krystof7059 4 жыл бұрын
on mac its with / and on windows its just SDL.H
@openmarkand
@openmarkand 4 жыл бұрын
@@krystof7059 no, you have to configure your build system but the official include convention as detailed on the official documentation is SDL.h. that's how CMake configuration packages and pkg-config files are configured when you invoke them.
@wicqedeyebot5631
@wicqedeyebot5631 7 жыл бұрын
Please help me, I am stuck at when I type make. It came up with this: make: *** No rule to make target 'hello_window.o', needed by 'game'. Stop.
@thomaslively8177
@thomaslively8177 7 жыл бұрын
Hi John, please make sure you're in the directory with all the .c files when you run `make`!
@wicqedeyebot5631
@wicqedeyebot5631 7 жыл бұрын
I am in the right directory /Downloads/sdl_seminar-master$. I have been trying to find solution the whole night but it still came up with this: clang -o game hello1_sdl.o `sdl2-config --libs --cflags` -ggdb3 -O0 --std=c99 -Wall -lSDL2_image -lm /usr/bin/ld: cannot find -lSDL2_image clang: error: linker command failed with exit code 1 (use -v to see invocation) Makefile:26: recipe for target 'game' failed make: *** [game] Error 1 . Any idea to make it work without any error as I have never use or install SDL on linux before but I have been programming c on cli.
@fonkytommy
@fonkytommy 5 жыл бұрын
www.cs.swarthmore.edu/~newhall/unixhelp/howto_makefiles.html#adv
@fonkytommy
@fonkytommy 5 жыл бұрын
@@wicqedeyebot5631 Are you sure you installed libsdl2-image-2.0-0 ?
@TheUltimateLizard
@TheUltimateLizard 6 жыл бұрын
Thank you, Dr. Chase, that was very helpful.
@zayanimeriam6926
@zayanimeriam6926 7 жыл бұрын
when I try to run the make file I get this error : clang : not found recipe for target (blabla) failed
@zayanimeriam6926
@zayanimeriam6926 7 жыл бұрын
I installed clang via the command apt-get install clang and it worked lol
@becomeengineer
@becomeengineer 5 жыл бұрын
@@zayanimeriam6926 GOOD FOR YOU
@kataiho2192
@kataiho2192 7 жыл бұрын
IMG_Load does not exist? How do you import it? Also, why doesn't it come with SDL?
@Elsuisse
@Elsuisse 7 жыл бұрын
You should install SDL_image
@abdulkerimyalcn3911
@abdulkerimyalcn3911 4 жыл бұрын
can you write a game using allegro library in c can you heelp men thanks
@ThatOneAgarAgarioThePro
@ThatOneAgarAgarioThePro 7 жыл бұрын
how to dwonload this
@manuelkvarda5285
@manuelkvarda5285 4 жыл бұрын
I spend some time looking for lerning materal for game development wit C. I did not find annything useful. If i found something SDL based it was about C++ and not C. So is it just my personal preference which language i choose at the énd ? what are the benefits of using pure C insead of C++ with SDL ?
@wiktorwektor123
@wiktorwektor123 3 жыл бұрын
Making games is difficult even for professionals. You don't want to make it more difficult than it already is. Use language that you like typing code in. It will be one less hassle in game dev. Booth C and C++ are capable to make AAA games. If you think C is simpler, more fun or you just hate OOP then stick to C. If you can't live without OOP or you need templates and you think that C is too simple then use C++. For end user who will be playing your game it doesn't matter at all. I personally use C, because it fits my style more, but thats my personal preference. As a bonus I get faster compile times, because C and it's compiler is much simpler.
@zayanimeriam6926
@zayanimeriam6926 7 жыл бұрын
Undefined reference to SDL_INIT . why? I installed sdl just like in the tutorial?
@fonkytommy
@fonkytommy 5 жыл бұрын
There is no SDL_INIT. I think you wanted to use SDL_Init() --- >It's a function. SDL hints are ALL CAPS and function are like SDL_Function.
@RainingArtillery
@RainingArtillery 4 жыл бұрын
This is for when C++ just doesn't bring enough tears and pain
@antohamusician
@antohamusician 4 жыл бұрын
Fk C++ ))
@giancarloandrebravoabanto7091
@giancarloandrebravoabanto7091 4 жыл бұрын
damn lm about to watch this video. what l was doing all this years?
@axpanos
@axpanos 7 жыл бұрын
Thank you mit
@pchandu1995
@pchandu1995 8 жыл бұрын
which debian linux distro is that ?
@pchandu1995
@pchandu1995 8 жыл бұрын
thanks for the link,it's a Ubuntu based,maybe vanilla debian,by custom VM you mean all the dependency,packages are preinstalled for this cs50(SDL)
@AlexanderEndless
@AlexanderEndless 3 жыл бұрын
Why nothing for Windows?
@kitsumi02
@kitsumi02 3 жыл бұрын
It's for windows too
@rolandbrake
@rolandbrake 7 жыл бұрын
where i can find the source code?
@thomaslively8177
@thomaslively8177 7 жыл бұрын
Hi Roland, you can find the source code here: github.com/tlively/sdl_seminar
@tessiof
@tessiof 5 жыл бұрын
There's no libsdl2-dbg package in Ubuntu anymore.
@LANstorm.
@LANstorm. 5 жыл бұрын
okay
@tessiof
@tessiof 5 жыл бұрын
@@LANstorm. okay you too
@LANstorm.
@LANstorm. 5 жыл бұрын
@@tessiof thanks for the info.
@krystof7059
@krystof7059 4 жыл бұрын
download it from official sites
@juniorsantosjerry4188
@juniorsantosjerry4188 5 жыл бұрын
and how configure SDL to Visual Studio 2010?
@Omar_Little
@Omar_Little 8 жыл бұрын
I assume this is for people that are very adept C programmers?
@blackoutgo2597
@blackoutgo2597 8 жыл бұрын
if you’ve finished cs50, im guessing that should be enough
@abandoned7501
@abandoned7501 5 жыл бұрын
No, you just need to learn math, a lot of math
@Thelavendel
@Thelavendel 7 ай бұрын
should you still make games with these things?
@EvilRamin
@EvilRamin 7 ай бұрын
If it's just a simple project, then why not?
@Thelavendel
@Thelavendel 7 ай бұрын
@@EvilRamin you could make it a hell of a lot simpler using some other tools?
@gadourmn3150
@gadourmn3150 6 жыл бұрын
Is this useful for windows compiles?
@ignacionr
@ignacionr 4 жыл бұрын
In general, good stuff. Just please pay a bit of attention and learn how to use the flags gotten from sdl2-config; the idea is that when you pass "--cflags" you put that on the c compiler flags, and "--libs" is for LDFLAGS (for the linker) that is the reason you get those warnings.
@TheUltimateLizard
@TheUltimateLizard 6 жыл бұрын
You were wrong about Unions. They are made to store only one of the specified types of data, and they output only one and the most recently added data. They don't store 'the largest data' in it, as you said.
@thomaslively8177
@thomaslively8177 6 жыл бұрын
Hi Michael, it's true that unions only hold one of their members at a time, but in order to do that their size in memory needs to be the same as the size of their largest possible contents. They do not change their size in memory depending on what member had the latest store.
@abdelrebel-m5g
@abdelrebel-m5g 5 ай бұрын
libsdl2-2.0-0 libsdl2-dbg libsdl2-dev libsdl2-image-2.0-0 libsdl2-image-dbg libsdl2-image-dev
@이은서-x7h
@이은서-x7h 4 жыл бұрын
sorry,,,but can you make korean subtitles?
@faab_02
@faab_02 7 жыл бұрын
That's an awesome introduction but I still have a small problem github.com/tlively/sdl_seminar.git this link works well but I can't sdl_seminar-master
@zayanimeriam6926
@zayanimeriam6926 7 жыл бұрын
Why doesn t this work for meeee T-T
@mahee96
@mahee96 4 жыл бұрын
Does it still not work? ....just curious 😬
@mikedev5263
@mikedev5263 2 жыл бұрын
2022
@locomotivere4497
@locomotivere4497 4 жыл бұрын
sudo apt install mono-devel sudo apt install mflag linux
@gabrielwilliams6373
@gabrielwilliams6373 4 жыл бұрын
Nobody: Thomas Lively: The human eye only sees 12FPS.
@UltimatePiccolo
@UltimatePiccolo 5 жыл бұрын
I appreciate the tutorial, but why the hell linux? Why not default to Windows?
@LANstorm.
@LANstorm. 5 жыл бұрын
because linux is superior to windows.
@UltimatePiccolo
@UltimatePiccolo 5 жыл бұрын
@@LANstorm. debatable.
@LANstorm.
@LANstorm. 5 жыл бұрын
@@UltimatePiccolo no not really.
@UltimatePiccolo
@UltimatePiccolo 5 жыл бұрын
@@LANstorm. yes, yes really.
@LANstorm.
@LANstorm. 5 жыл бұрын
@@UltimatePiccolo no.
@texturator936
@texturator936 7 жыл бұрын
Very nice tutorial. There were one mistake, or lack of detail. TV and Film: 25 frames per second PAL, and 30 frames per second NTSC world. While Movies in cinema got 24 frames. (That gives special look, with smooth camera movement, and bigger screen, for immersion ) Computer screen movies: usually 30 fps, and new hype on 60fps :)
@BoredChinese
@BoredChinese 7 жыл бұрын
It's CS bud, not film school. What you're saying is already unnecessary information. Computer screen movies? What? If you check the refresh rate of today's monitors then they are almost always 60hz, unless you get a 144hz monitor.
@hetaeramancer
@hetaeramancer Жыл бұрын
this should be named "tutorial on setting up sdl and makefile" ! >:( smh...
@cinder9245
@cinder9245 6 жыл бұрын
CXXXXXX
@duongtricker9531
@duongtricker9531 6 жыл бұрын
huhu Im vietnamese I don stan enythink
@bahayesilyurt1510
@bahayesilyurt1510 5 жыл бұрын
what a meme
@voiceoftreason1760
@voiceoftreason1760 5 жыл бұрын
My PC runs linux. PC is not another word for Windows.
Creating a Game Loop with C & SDL (Tutorial)
1:50:46
pikuma
Рет қаралды 59 М.
99.9% IMPOSSIBLE
00:24
STORROR
Рет қаралды 25 МЛН
Accompanying my daughter to practice dance is so annoying #funny #cute#comedy
00:17
Funny daughter's daily life
Рет қаралды 28 МЛН
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 53 МЛН
Game Development with SDL 2.0 (Steam Dev Days 2014)
51:11
Steamworks Development
Рет қаралды 229 М.
Advice for Writing Small Programs in C
1:45:24
Sean Barrett
Рет қаралды 152 М.
Why do we use SDL with C & C++?
16:26
pikuma
Рет қаралды 46 М.
Making a Game With C++ and SDL2
5:34
Goodgis
Рет қаралды 656 М.
Creating a window - Software from Scratch
1:04:12
Muukid
Рет қаралды 154 М.
Dear Game Developers, Stop Messing This Up!
22:19
Jonas Tyroller
Рет қаралды 748 М.
I made the same game in Assembly, C and C++
4:20
Nathan Baggs
Рет қаралды 817 М.
Section 4 - inf-zone: Einführung in die Informatik
1:09:52
inf-zone: Einführung in Informatik
Рет қаралды 20
Coding Graphics in C: SetPixel, LineDraw, Moire and More!
8:36
Dave's Garage
Рет қаралды 148 М.
Creating a Doom-style 3D engine in C
18:50
Bisqwit
Рет қаралды 962 М.