SDL2 Tutorial: How To Draw and Render Using C++

Поділитися
Вставка
  • Опубліковано 31 січ 2025

КОМЕНТАРІ • 34

  • @TheBuilder
    @TheBuilder  2 роки тому +4

    Subscribe for more

  • @AliRaza-gd3lk
    @AliRaza-gd3lk 2 роки тому +8

    This is such a thorough tutorial. Helped me a lot!

  • @gasparliboreiro4572
    @gasparliboreiro4572 Рік тому

    love the comprehensive explanation, gonna watch more

  • @Shovelzzzz
    @Shovelzzzz Рік тому +9

    Light theme is a crime... Great tutorial though!

    • @TheBuilder
      @TheBuilder  Рік тому +5

      Light theme is best theme, I'm not in the business of making my editor look like a 1990s hacker movie. I read a lot and the only people who prefer dark theme seem to be new programmers.

    • @Tomab3
      @Tomab3 Рік тому +2

      Light theme attracts bugs

    • @Iamanugget111
      @Iamanugget111 11 місяців тому +3

      i am not new and i hate light mode it destroys my eyes

  • @Steven-dt2sh
    @Steven-dt2sh Рік тому +4

    Hey, I was having some issues with the vector and the forloop using the emplace_back "C2661: no overloaded function takes 2 arguments"
    I'm not sure why it was not allowing me to use this on the vector but what i ended up doing is using the push_back function:
    -(below std::vector v BUT outside the forloop) SDL_Point temp;
    - (Inside for loop) temp.x = rand() % 640;
    - (right below that line) temp.y = rand() % 480;
    - (right below that line) v.push_back(temp);
    Not sure why i got that message but i got the same result using push_back

    • @marektengler6033
      @marektengler6033 11 місяців тому

      Had same problem thx!

    • @tuhaggis
      @tuhaggis 8 місяців тому

      Had this problem too, and your solution worked. Well explained, thank you.

  • @dovydasgirskas5427
    @dovydasgirskas5427 9 місяців тому

    wonderful tutorial. thank you!

  • @marian8395
    @marian8395 Рік тому +1

    Tried using SDL2 in VSCodium on Arch but always got the error : "main.cpp:(.text+0x2d): undefined reference to `SDL_Init' ". Any idea what this could be? Thanks a lot.

  • @tylerfife8279
    @tylerfife8279 Рік тому

    Thanks a bunch, been having such a headache learning how to use this library, as graphics.h does not work on wayland. Saved me so much time.

  • @chigozie123
    @chigozie123 10 місяців тому

    Is it possible to set the renderer to be transparent?

  • @Flanksss
    @Flanksss 3 роки тому

    Hello, when I run my programs, the window is not moveable, and I can not close the window using the window itself, I instead have to close the CMD window. Is there a fix to this?

    • @TheBuilder
      @TheBuilder  3 роки тому

      You need to poll for the event that handles closing the window, I talk about it in the video on mouse and keyboard events

  • @rodrigoqteixeira
    @rodrigoqteixeira Рік тому

    can someone tell me how to setup the sdl.h file?? (preference without ides...) when i downloaded it gave me an dll and a readme

    • @famishedcrane2596
      @famishedcrane2596 Рік тому

      Try moving 'SDL2.frameworks' into your frameworks folder. Assuming you're on Mac

    • @rodrigoqteixeira
      @rodrigoqteixeira Рік тому

      @@famishedcrane2596 no, im in windows... (Windows 10 64 bits)

    • @famishedcrane2596
      @famishedcrane2596 Рік тому

      ​@@rodrigoqteixeira

  • @gasparliboreiro4572
    @gasparliboreiro4572 Рік тому

    I love your tutorials but the hardest part of following them is to get sdl2 installed, I'm getting bald with the ammout of errors and videos that work but not whey I try, I wish youn made a compehensive video about installing dependencis for c++ usage

    • @TheBuilder
      @TheBuilder  Рік тому

      are you on linux/mac/windows? it really depends on your operating system. It's a slow process but getting the build setup once is the most important part of development.

    • @gasparliboreiro4572
      @gasparliboreiro4572 Рік тому

      @@TheBuilder I'm on Windows compiling with g++, I think I finally got it but I don't understand nothing about how all this works, I get the header files, like they are where I get all my functionalities and all of that, but all the linker and lib stuff goes over my head

    • @TheBuilder
      @TheBuilder  Рік тому +1

      @@gasparliboreiro4572 I'm sorry but the last time I did any C++ development on windows, was about 14 years ago. Idk if I could be any help on this front

  • @deadlyorchard
    @deadlyorchard Рік тому +2

    intersection.

  • @mrdouble
    @mrdouble 2 роки тому +1

    This is the 2nd tutorial of yours that I've ALMOST completed.This tutorial and the spinning cube in SDL2 works great up until I use the emplace_back function and then it breaks. Ive commented out the "v.emplace_back(rand() % 640, rand() % 480);" and it compiles fine.
    Any Idea?
    :\mingw\lib\gcc\mingw32\6.3.0\include\c++\ext
    ew_allocator.h:120:4: error: new initializer expression list treated as compound expression [-fpermissive]
    { ::new((void *)__p) _Up(std::forward(__args)...); }
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\ext
    ew_allocator.h:120:4: error: no matching function for call to 'SDL_Point::SDL_Point(int)'
    In file included from C:/SDL2-W-image/include/SDL2/SDL_video.h:33:0,
    from C:/SDL2-W-image/include/SDL2/SDL_events.h:33,
    from C:/SDL2-W-image/include/SDL2/SDL.h:41,
    from C:\Users\Admin\OneDrive\Documents\VSCodeProj\SDL2_Tutorials\.vscode\basic.cpp:1:
    C:/SDL2-W-image/include/SDL2/SDL_rect.h:48:16: note: candidate: SDL_Point::SDL_Point()
    typedef struct SDL_Point
    ^~~~~~~~~

    • @TheBuilder
      @TheBuilder  2 роки тому +2

      try replacing emplace_back with push_back you just need to change it to something like this .push_back(SDL_Point(x,y))
      hope that helped

    • @mrdouble
      @mrdouble 2 роки тому +1

      @@TheBuilder I'm so sorry, can you be a little bit more explicit? I know your busy so no biggie if you can't. BTW, I really do love your vids

    • @TheBuilder
      @TheBuilder  2 роки тому +2

      v.push_back(SDL_Point(rand() % 640, rand() % 480));

    • @mrdouble
      @mrdouble 2 роки тому +3

      @@TheBuilder My working solution is below...Any idea why SDL_Point has to be initialized before emplace_back can be used? Push_back didnt work either until I initialized in same manner.
      for (int i = 0; i < 100000; i++) {
      SDL_Point point = { rand() % 640, rand() % 480 };
      v.emplace_back(point);

    • @addisoncham6225
      @addisoncham6225 3 місяці тому

      @@mrdouble v.emplace_back(SDL_Point{ rand() % 640, rand() % 480 });
      This works too