Writing 2D Games in C using SDL by Thomas Lively

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ม.ค. 2025

ความคิดเห็น •

  • @hsinhunglin9108
    @hsinhunglin9108 5 ปีที่แล้ว +329

    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 4 ปีที่แล้ว

      @Zed hahahaha

    • @m3hdim3hdi
      @m3hdim3hdi 3 ปีที่แล้ว +28

      “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 ปีที่แล้ว +1

      @@m3hdim3hdi WTF LOL

    • @dancom6030
      @dancom6030 ปีที่แล้ว +1

      @@haseldanprince9658 object orientation is pretty easy to emulate in C when it is necessary.

  • @reconmaster907
    @reconmaster907 4 หลายเดือนก่อน +6

    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 3 หลายเดือนก่อน +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 ปีที่แล้ว +9

    5 years later, still useful. Thumbs up.

  • @qwerty273
    @qwerty273 3 ปีที่แล้ว +15

    By far the best video I’ve watched so far on SDL with C. Quick, and easy.

  • @joshli5309
    @joshli5309 7 ปีที่แล้ว +9

    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 ปีที่แล้ว +8

      Hi Josh, I'm glad you found the seminar helpful! Good luck in your projects :)

  • @harriscrews1282
    @harriscrews1282 4 ปีที่แล้ว +12

    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!

  • @a.v7998
    @a.v7998 9 หลายเดือนก่อน

    Loved it man. This is the best SDL tutorial with C language!

  • @vaslot
    @vaslot 6 ปีที่แล้ว +9

    Awesome presentation! I am new to SDL 2 programming and loved it. Thank you!

  • @_trion
    @_trion 8 ปีที่แล้ว +59

    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 ปีที่แล้ว +14

      github.com/tlively/sdl_seminar/
      he told us where to get the code during the first 5 minutes of the video...

    • @jonathanmoore5619
      @jonathanmoore5619 3 ปีที่แล้ว +1

      @@juanpisani9297 coding is "not for you", Jen...

  • @nyume815
    @nyume815 6 ปีที่แล้ว +2

    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!

  • @NeilRoy
    @NeilRoy 8 ปีที่แล้ว +10

    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 ปีที่แล้ว +3

      Thanks, I'm in the exact same situation and was tired of making ASCII graphics for my game.

  • @yusufmalikul
    @yusufmalikul 2 ปีที่แล้ว

    As of today (2022) your code still works, and I use a mac. Thanks!

  • @michaelwoodruff5752
    @michaelwoodruff5752 7 ปีที่แล้ว +13

    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.

  • @UnifyRadar
    @UnifyRadar หลายเดือนก่อน

    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.

  • @ГерриПитт
    @ГерриПитт 4 ปีที่แล้ว

    Thanks, man! Really really helpful introduction to SDL!

  • @karimkohel3240
    @karimkohel3240 5 ปีที่แล้ว +4

    cs5 does it again. thank you guys so much for everything

  • @atiedebee1020
    @atiedebee1020 3 ปีที่แล้ว +1

    This tutorial was great, thank you for this!

  • @FernandoBasso
    @FernandoBasso 8 ปีที่แล้ว +5

    Wow! This lesson is overwhelmingly informative. Thanks a lot! Superb work!!!

  • @beb9632
    @beb9632 3 ปีที่แล้ว +6

    Me: Im gonna write a game with SDL!
    Segmentation fault (core dumped): Hello

    • @abhilashsinha115
      @abhilashsinha115 3 ปีที่แล้ว +1

      That's exactly the perfect way to get started, cheers mate!!

    • @not_herobrine3752
      @not_herobrine3752 2 ปีที่แล้ว

      its been seven months, any further progress?

  • @syedbaryalay5849
    @syedbaryalay5849 5 ปีที่แล้ว +3

    great presentation mate, nice intro this crazy hell

  • @lev4392
    @lev4392 3 ปีที่แล้ว

    Super, super helpful! Thank you so much!

  • @AikHuMuslim
    @AikHuMuslim 2 ปีที่แล้ว

    Thanks for the great content for the c language

  • @altaghyeer
    @altaghyeer 3 ปีที่แล้ว

    very good presentation
    thank you very much

  • @alaindevtecchannel2232
    @alaindevtecchannel2232 3 ปีที่แล้ว +1

    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.

  • @electricimpulsetoprogramming
    @electricimpulsetoprogramming 2 ปีที่แล้ว

    this guy explains very good

  • @gabrielbap1
    @gabrielbap1 3 ปีที่แล้ว

    Great class!

  • @abraham4374
    @abraham4374 6 ปีที่แล้ว

    Loved this video

  • @evildiesel1709
    @evildiesel1709 7 ปีที่แล้ว +1

    Excellent tutorial! Gonna give it a bash now:)

  • @salimtrabelsi2163
    @salimtrabelsi2163 5 ปีที่แล้ว +1

    thanks man its really helpful 😍❤❤

  • @LisandroLorea
    @LisandroLorea 3 ปีที่แล้ว +1

    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!

  • @katiacor
    @katiacor 3 ปีที่แล้ว

    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!

  • @kevinnudel9682
    @kevinnudel9682 3 หลายเดือนก่อน

    Thank you.

  • @chronicsnail6675
    @chronicsnail6675 4 ปีที่แล้ว

    You are the best thanks alot !

  • @RedQueenOfficial
    @RedQueenOfficial 7 ปีที่แล้ว

    Awesome

  • @yashwanthcb
    @yashwanthcb 8 ปีที่แล้ว +7

    I would feel happy if cs50 provides a tutorial on openGL/c++

    • @kopuz.co.uk.
      @kopuz.co.uk. 6 ปีที่แล้ว +3

      get a book.

    • @aidensmith6277
      @aidensmith6277 6 ปีที่แล้ว +2

      @@kopuz.co.uk. we got a negative nancy here xd

    • @kopuz.co.uk.
      @kopuz.co.uk. 6 ปีที่แล้ว +2

      @@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!

  • @chesterhackenbush
    @chesterhackenbush 7 ปีที่แล้ว

    Excellent!

  • @TheUltimateLizard
    @TheUltimateLizard 6 ปีที่แล้ว

    Thank you, Dr. Chase, that was very helpful.

  • @PaketNAParkete
    @PaketNAParkete 6 ปีที่แล้ว +7

    Спасибо большое за видео! мы изучаем эту библиотеку в университете, но преподаватели не очень хорошо нам её объясняют. Мы даже не догадывались, что есть официальный сайт с подробным описанием каждой функции.

    • @TheUltimateLizard
      @TheUltimateLizard 6 ปีที่แล้ว +2

      Что за университет и что за факультет?

  • @GCKteamKrispy
    @GCKteamKrispy 7 หลายเดือนก่อน

    CS50 please make this course for 3D in GD50

  • @RJPG_7
    @RJPG_7 4 หลายเดือนก่อน

    Can i do that in termux?

  • @rambabuupreti5669
    @rambabuupreti5669 6 ปีที่แล้ว +3

    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 ปีที่แล้ว +1

      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.

  • @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 ปีที่แล้ว +1

      This should work with almost no modification on a linux distro like Ubuntu as well.

  • @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 ปีที่แล้ว +1

      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 ?

  • @manuelkvarda5285
    @manuelkvarda5285 5 ปีที่แล้ว +3

    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 ปีที่แล้ว +1

      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.

  • @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.

  • @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 ปีที่แล้ว +4

      I installed clang via the command apt-get install clang and it worked lol

    • @becomeengineer
      @becomeengineer 5 ปีที่แล้ว +3

      @@zayanimeriam6926 GOOD FOR YOU

  • @abdulkerimyalcn3911
    @abdulkerimyalcn3911 4 ปีที่แล้ว

    can you write a game using allegro library in c can you heelp men thanks

  • @kataiho2192
    @kataiho2192 7 ปีที่แล้ว

    IMG_Load does not exist? How do you import it? Also, why doesn't it come with SDL?

    • @Elsuisse
      @Elsuisse 7 ปีที่แล้ว +5

      You should install SDL_image

  • @openmarkand
    @openmarkand 4 ปีที่แล้ว

    SDL include convention is SDL.h only though.

  • @giancarloandrebravoabanto7091
    @giancarloandrebravoabanto7091 5 ปีที่แล้ว +3

    damn lm about to watch this video.
    what l was doing all this years?

  • @axpanos
    @axpanos 7 ปีที่แล้ว +1

    Thank you mit

  • @ThatOneAgarAgarioThePro
    @ThatOneAgarAgarioThePro 7 ปีที่แล้ว +1

    how to dwonload this

  • @zayanimeriam6926
    @zayanimeriam6926 7 ปีที่แล้ว

    Undefined reference to SDL_INIT . why? I installed sdl just like in the tutorial?

    • @fonkytommy
      @fonkytommy 5 ปีที่แล้ว +2

      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.

  • @AlexanderEndless
    @AlexanderEndless 3 ปีที่แล้ว

    Why nothing for Windows?

    • @kitsumi02
      @kitsumi02 3 ปีที่แล้ว

      It's for windows too

  • @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)

  • @RainingArtillery
    @RainingArtillery 4 ปีที่แล้ว +3

    This is for when C++ just doesn't bring enough tears and pain

  • @juniorsantosjerry4188
    @juniorsantosjerry4188 5 ปีที่แล้ว

    and how configure SDL to Visual Studio 2010?

  • @rolandbrake
    @rolandbrake 7 ปีที่แล้ว +2

    where i can find the source code?

    • @thomaslively8177
      @thomaslively8177 7 ปีที่แล้ว +4

      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 ปีที่แล้ว +1

      okay

    • @tessiof
      @tessiof 5 ปีที่แล้ว +1

      @@LANstorm. okay you too

    • @LANstorm.
      @LANstorm. 5 ปีที่แล้ว +2

      @@tessiof thanks for the info.

    • @krystof7059
      @krystof7059 4 ปีที่แล้ว

      download it from official sites

  • @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 ปีที่แล้ว +7

      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.

  • @Omar_Little
    @Omar_Little 8 ปีที่แล้ว +2

    I assume this is for people that are very adept C programmers?

    • @blackoutgo2597
      @blackoutgo2597 8 ปีที่แล้ว +6

      if you’ve finished cs50, im guessing that should be enough

    • @abandoned7501
      @abandoned7501 6 ปีที่แล้ว

      No, you just need to learn math, a lot of math

  • @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

  • @이은서-x7h
    @이은서-x7h 4 ปีที่แล้ว

    sorry,,,but can you make korean subtitles?

  • @Thelavendel
    @Thelavendel 8 หลายเดือนก่อน

    should you still make games with these things?

    • @EvilRamin
      @EvilRamin 8 หลายเดือนก่อน

      If it's just a simple project, then why not?

    • @Thelavendel
      @Thelavendel 8 หลายเดือนก่อน

      @@EvilRamin you could make it a hell of a lot simpler using some other tools?

  • @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.

  • @abdelrebel-m5g
    @abdelrebel-m5g 6 หลายเดือนก่อน

    libsdl2-2.0-0 libsdl2-dbg libsdl2-dev libsdl2-image-2.0-0 libsdl2-image-dbg libsdl2-image-dev

  • @gabrielwilliams6373
    @gabrielwilliams6373 4 ปีที่แล้ว +2

    Nobody:
    Thomas Lively: The human eye only sees 12FPS.

  • @gadourmn3150
    @gadourmn3150 6 ปีที่แล้ว

    Is this useful for windows compiles?

  • @mikedev5263
    @mikedev5263 2 ปีที่แล้ว

    2022

  • @zayanimeriam6926
    @zayanimeriam6926 7 ปีที่แล้ว +2

    Why doesn t this work for meeee T-T

    • @mahee96
      @mahee96 4 ปีที่แล้ว

      Does it still not work? ....just curious 😬

  • @locomotivere4497
    @locomotivere4497 4 ปีที่แล้ว

    sudo apt install mono-devel
    sudo apt install mflag
    linux

  • @UltimatePiccolo
    @UltimatePiccolo 5 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      @@UltimatePiccolo no not really.

    • @UltimatePiccolo
      @UltimatePiccolo 5 ปีที่แล้ว

      @@LANstorm. yes, yes really.

    • @LANstorm.
      @LANstorm. 5 ปีที่แล้ว +1

      @@UltimatePiccolo no.

  • @hetaeramancer
    @hetaeramancer ปีที่แล้ว

    this should be named "tutorial on setting up sdl and makefile" ! >:( smh...

  • @cinder9245
    @cinder9245 6 ปีที่แล้ว

    CXXXXXX

  • @texturator936
    @texturator936 8 ปีที่แล้ว +1

    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 ปีที่แล้ว +12

      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.

  • @duongtricker9531
    @duongtricker9531 6 ปีที่แล้ว +1

    huhu Im vietnamese I don stan enythink

  • @voiceoftreason1760
    @voiceoftreason1760 5 ปีที่แล้ว

    My PC runs linux. PC is not another word for Windows.