For Visual Studio Programmers, the biggest (and smallest) issue I had was giving me LNK issues. The solution for me was in main.cpp. Remove the "const" type from "const char * argv[]" in the main function. It took way to long to figure this out, hope it helps someone.
For the longest time I could not figure out how to separate SDL into a game engine without the entire project falling apart. Thank you for helping me break through this barrier and into much more complex game designs!
There are some issues with this code... 1) If SDL fails to create a window you don't want to then attempt to create a renderer. 2) Likewise if the renderer fails to initialize you don't want to set isRunning and start the update loop. 3) Because initialization can fail you should really be returning success/failure from this routine so that it can be handled appropriately. Also a speed tip for those watching, after you have defined your class, just copy paste that into the cpp file. You don't need to type it all out again. You can replace the semi colons with open close braces and you are good to go, it will save you a tonne of time.
Pain in the arse, what program doesn't have an int main(), why did they even think of this as a weird edge case. Literally the first google search for "unresolved external symbol main", gives you a stack overflow article, and the second answer tells you about SDL_MAIN_HANDLED
@@Kokurorokuko I really wasnt trying to be that harsh its just like we learned that in the mandatory CIS 101 for all students in freshmen year at my Junior college... its just hella easy to tell when people have never had any formal instruction... (protip, move to a state with socialized college, get wage-slave job to pay bills, wait one year to qualify as resident... profit)
Hi, just a question: Why did you define the game variable in the global scope and not inside the main function itself? Also why did you create it on the heap using new? And should it not because of that be explicitly removed using 'delete game' after the cleanup? thanks in advance!
All this at 21:40 does is create linker errors: LNK2019 unresolved external symbol SDL_SetRenderDrawColor referenced in function "public: void __cdecl Game::init(char const *,int,int,int,int,bool)" (?init@Game@@QEAAXPEBDHHHH_N@Z) is the first one... Edit: make sure to watch the first video again in that case, I didn't add in linker - > input the dependencies... Also, there seems to be a naming conflict with the main function already being defined so somewhere so changing it to char* argv[] instead of const char* argv[] seems to fix that or you can #undef main in main.cpp... but I don't really understand so maybe it won't work for you :'(
19:05 what are you doing here? what is "Game *game"? because when I compile it gives me an error saying "game" was not defined in this scope even though I followed the tutorial to a T.
I do not know, and i hope anyone out their is needing this at this moment. Here it is, download SDL with Brew, I have no CLUE what it did but i downloaded all the libraries needed and it is working now. thank you for my ted talk
I started doing this in Visual Studio and straight from the start I'm confused about making a new source file; it only creates a "Name".cpp but no .hpp. It might be because of the IDE, but I'm not sure, it's my first time making a game... Also, I've been following another tutorial but it only goes so far as creating a game window with a picture on it(I guess I made it using SDL libraries, but I'm unsure), nothing besides it, now I do know C++(I do not know SDL tho), and I have 0 clue of how to start making my game. Would you suggest I start from scratch following your tutorial or I could keep the other code? Here's the code if you're interested(ignore the comments, it's for me to understand what I did): #include #include #include const int WIDTH = 800, HEIGHT = 600; //WIDTH i HEIGHT imaju dodeljene vrednosti koje predstavljaju //sirinu i duzinu prozora int main(int argc, char *argv[])//parametri su neophodni zbog SDL-a { SDL_Surface *imageSurface = NULL; //kreiraju se SDL surface(povrsine) SDL_Surface *windowSurface = NULL; //ovo ce biti povrsina prozora koji smo ovde kreairali(prozor je kao platno) if (SDL_Init(SDL_INIT_EVERYTHING) < 0) //ispituje se inicijalizacija svega u SDL-u { std::cout
Hey Ive only been programming in c# so far and you are using all that stuff in the game class like its static is that just by default in cpp or is there something behind that?
Thank you so much for your work. These videos are marvelous. If you don't mind a question though, I was following along with a different tutorial as well and they used "if( SDL_Init( SDL_INIT_VIDEO ) < 0 )" instead of "if (SDL_Init(SDL_INIT_EVERYTHING) == 0) {" and I was wondering if you have an opinion on this or not. For games is it simply just best to init everything all at once?
Thanks. This was a good start for me. I'm taking a data structures class next semester and so I decided to try to make a simple playing card game I made up as a way to brush up on my c++ and hopefully I will have a portfolio piece to add to my resume. I'm using Eclipse in Kubuntu 22.04 and I was getting all the dreaded SDL undefined reference errors. I tried adding it to the linker and every other suggestion and finally deleted and purged both Eclipse and SDL2 and reinstalled both using the C++ version download from the Eclipse website. SDL I downloaded using apt and this series libsdl2-dev libsdl1.2-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev. Then I started a new Eclipse C++ and added SDL2 to the linker and path to the compiler includes. Now everything is working.
For anyone on a Mac having trouble getting the window to show up, I found a post on SO that fixed the problem. Add this loop to your code instead of the SDL_Delay, and it will show up: // A basic main loop to prevent blocking bool is_running = true; SDL_Event event; while (is_running) { while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { is_running = false; } } SDL_Delay(16); }
@@MrEvilyogurt "When C++ was originally designed, all of the identifiers in the C++ standard library (including std::cin and std::cout) were available to be used without the std:: prefix (they were part of the global namespace). However, this meant that any identifier in the standard library could potentially conflict with any name you picked for your own identifiers (also defined in the global namespace). Code that was working might suddenly have a naming conflict when you #included a new file from the standard library. Or worse, programs that would compile under one version of C++ might not compile under a future version of C++, as new identifiers introduced into the standard library could have a naming conflict with already written code. So C++ moved all of the functionality in the standard library into a namespace named “std” (short for standard)." This basically means by putting using namespace std; at the top of your program subjects you to all the above issues stated with having standard library in your global namespace.
Thanks so much for this series! Love your pacing and information level ^^ hoping I can keep up through the whole tutorial. Just started with newest VC and SDL2 builds, everything working great so far. Cheers!
If your app crashes before it ever shows the window: I was getting a crash before my window would load with an error like "library not loaded no suitable image found" for SDL2. And something else about a matching team ID I fixed it by: 1. going to Project Settings > Build Settings > Other Liner Flags > Add "-framework SDL2" 2. going to Project Settings > Signing & Capabilities > Hardened Runtime > Check the box next to "Disable Library Validation" 3. in Project Settings > Signing & Capabilities > Signing > "Automatically manage signing" is checked, I have my personal account chosen for "Team", I have "Signing Certificate" set to "Sign to Run Locally" Hopefully, after you set all these as described above, Clean, Build, and Run it will work.
trying to follow along on VS. Having some frustrating bugs Game.cpp(8,95): error C2761: 'void Game::init(const char *,int,int,int,int,bool)': redeclaration of member is not allowed Game.cpp(9,1): error C2447: '{': missing function header (old-style formal list?) I cant get it to run and cant figure out why, anyone know what's going on?? the second one is particularly frustrating bc the code mirrors the video
For your error handling in the Init method couldn’t you use SDL_Log() and SDL_GetError() eg. SDL_Log(“Unable to initialise SDL: %s”, SDL_GetError()); Instead of having to include iostream, or doesn’t it really effect performance that much?
Hey, it's been a while since I took time to continue your tutorial but I had an assignment in class where I had to work with SDL and classes. I took on the half finished tutorial I had made and it just works so well. I was able to add Physics components with physics and lateupdate I used the GameObject to manage the entity pointer and manager reference, I added an int for the layer in the map file... when I'll have more time I'll redo the whole tutorial from the beggining. I wondered though... my teachers insists on us using cpp files for logic and I noticed your components don't seem to use them and I was wondering if there was a reason why or if it was just a stylistic question.
No. The next day he probably said he was going to look at a Da Vinci painting every single day until he memorized the strokes, and then create his first rectangle house.
Hello, im getting a strange error when i try to compile. Variable 'Game::isRunning' is uninitialized aswell as renderer and window. i have been trying to find solution but cannot find anything.
Great tutorials. What happens if you call init() more than once? Shouldn't you check the window and renderer exist and destroy them before creating new ones? or would SDL handle that. Thanks.
Yes, we can do that, but we will have to delete the game object explicitly at the end of main(). Game's Destructor function doesnt get called automatically when the program terminates.
I'm using codeblocks and get the following errors: Game.cpp||In function 'void init(const char*, int, int, int, int, bool)':|error: 'window' was not declared in this scope| Game.cpp|19|error: 'renderer' was not declared in this scope| Game.cpp|24|error: 'isRunning' was not declared in this scope| Game.cpp|27|error: 'isRunning' was not declared in this scope| Game.cpp||In member function 'void Game::clean()':| Game.cpp|53|error: 'SDL_QUIT' cannot be used as a function| Any help would be appericiated
If people are using visual studio and are still getting errors after trying all the different solutions, try putting #undef main under #include "Game.h" in the main file
@Der Absender I believe it's because the "SDL.h" header includes a header called "SDL_main.h" which has a declaration for the main function with the signature int main(int argc, char *argv[]). If you write a plain main definition as int main(), that puts a 2nd valid main function definition in the global scope. #undef main before YOUR main will remove the definition SDL has put in place and remove the ambiguity. Another way to solve it is to just declare main with the parameters (int argc, char *argv[]) to match the declaration SDL has. Hope this helps a week later.
in the Game.hpp file, you should set `bool isRunning=false` instead of just `bool isRunning` in order to avoid an infinite loop when Game is not initialized
You don't need an init() function, you should be using the Game classes constructor, it is run automatically as soon as you create the Game object without any need to call init(). If you don't use a constructor, you may as well use C (which I actually prefer to be honest).
Neil Roy Hi Neil, it’s true that the game class could be initialised in the constructor, but I was in the mindset that doing it in an init function would allow me to reinitialise the game when I need it to be, not sure yet if I will be implementing restarts like this yet. I’ll be doing some sort of world/game manager at some point soon, so I’ll decide then. So yes it may end up in the constructor. For the use of c++ I will be using function templates and smart pointers later on in the series
Then call the function reset(). Requiring the class to be initialized after construction in order to make it operable is a violation of the RAII principle.
@@Skandalos Yes that would be best practice. Same goes for the allocated game object, much better to just create a local game object, so we have better control over when it is destroyed.
Hi, thank you really much for your tutorial ! Is it normal that when i run the program, it takes about 40 seconds to initialize SDL2 ? (By that i mean nothing, not even "system initialized" appears on the console before these 40 seconds) I am on Windows 10 using CodeBlocks ^^
Well i "corriged it" by removing the "if SDL_Init(SDL_INIT_EVERYTHING) == 0" check, i don't know why it was so slow to check for initialisation for me ._. But well, it's normal now that it's removed, thanks anyway x')
why did you choose to allocate your game obj on the heap. Also you spent the time to free the SDL stuff in the destructor but then didn't even free the game obj itself?
Can't get this to build... I'm at 21:40, trying to get the window to show, but I get these messages: main.cpp(4): error C2143: syntax error: missing ';' before '*' main.cpp(4): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int main.cpp(8): error C2061: syntax error: identifier 'Game' main.cpp(10): error C2065: 'SDL_WINDOWPOS_CENTERED': undeclared identifier Other than the first line which says #include "Game.h" because I'm on windows, my code is exactly the same as in the video (or at least I don't see any discrepancies). Is there something else I need to do to make this work on windows? Using Visual Studio 2017 Community
Figured it out. For everyone running into this problem: I started this solution as a console application and Visual Studio needs me to #include "pch.h" in this situation. Took me all weekend to realize that I have to #include "pch.h" BEFORE #include "Game.h".
The Error list says, that the "Game::isRunning", "Game::renderer" and the "Game::window" variables aren't initialised. "A Membervariable must always be initialised (type 6)."
Hey, I'm having an issue where every time I try to run the program I get an error saying that the application was unable to start (I'm on windows). Here's the full error code: The application was unable to start correctly (0xc000007b). Click ok to close the application. Any help would be much appreciated!
I got an error when creating a new game instance as a 'nullptr' (which is a keyword in C++11). So it wouldn't allow me to declare it as such. So I just used the following instead and it worked fine: Game *game = new Game(); Hope this helps.
Very nice tutorial, although a bit old and I have to say I had to resolve a few bugs here and there(no big deal, they were annoying tho), the very good thing about it is the fact that you organize everything so neatly... In other tutorials the code is just all in function main, wihtout any classes or managing code and it's all left to the viewer, along with all the issues that may come with organizing it all :P Overall, thanks for this tutorial! :D
GunnDawg There is a video on frame rate, and we will be using a ‘deltaTime’ system in the future. Just getting things done the simplest way then will be making things more robust as we progress with the engine and game.
Doing this on visual studio. I've worked a lot with c#, so I'm thinking I can jump right into this! I was wrong... for anyone facing a wall of 200 errors right off the bat, try messing with your includes until that error number reaches zero. Good luck!
I watched the previous video on how to set up SDL on windows, and coming from that tutorial to this one, I have no idea what I’m supposed to do. I have to create a completely different project? What about all that set up I just did?
The little Running() function in game class could be more aptly named GetIsRunning cause its essentially a getter. Also the init function has the problem of still saying its running even if window and renderer return false,plus theres no debug message if those are false also But im nitpicking.Nice tutorial anyway.
I'm trying to get my code to work, but when I run it at the end of this lesson, I get an error window named '2D_GameEngine.exe' saying "The application was unable to start correctly (0xc000007b). Click OK to close the application." When I try to use breakpoints on the main function, it still spits out the error. Can someone help me?
@@Nodal488 I was able to move past this problem, but I forgot what I did to fix the error. Oh I remember, I googled the error and found this page www.drivereasy.com/knowledge/how-to-fix-the-application-is-unable-to-start-correctly-0xc00007b-error/ I think I reinstalled the SDL2 package and it worked. I was using an external hard drive and had to move the downloaded files to get everything where it needed to be. After I reinstalled it was smooth sailing. Give that a try and let me know what you find!
IDK about mac, but windows needs: int main(int argc, char * argv[]){} as opposed to int main(int argc, const char * argv[]){} .... this was giving me a headache trying to figure out why it kept telling me 'undefined reference to SDL_main'
i mean the flags variable is set for your flags which you can assign to functions flags is initialized a value of 0 so instead of ''if (fullscreen)'' you could put other conditions like if (fullscreen == 1) {flags = SDL_WINDOW_FULLSCREEN;} and have another condition such as (fullscreen == 2) { flags = SDL_WINDOW_RESIZABLE;} You could rename ''fullscreen'' variable to ''screensize'' or something. It would take some reworking the code but nothing too difficult
Why are we defining the Game class in a separate file? I don't understand the benefit to that. Also, my SDL header is not being recognized by my Game.cpp/Game.hpp files. I am using visual studio 2017 professional. Aside from this infuriating problem, I'm loving your work. I really appreciate what you are doing. Thank you.
It's an old standard for developers that worked before things like Git were in widespread use. I personally just put my implementation code in the header file. Much less file clutter. It's also a lot easier to edit than jumping back and forth through files just to change the name of a class's private data member's name.
In visual studio 2019 Press Ctrl+. to trigger the Quick Actions and Refactorings menu and select Create Declaration / Definition from the context menu (quicker than typing)
Thank you for the wonderful tutorial! I ended up naming the Header with .h instead of .hpp. I ended up getting an error "LNK2019" unresolved external symbol: "public: bool_cdecl"... The pop-up error says, "Unable to run program...the system cannot find the file specified." Any and all help with be deeply appreciated! Thanks in advance, C
I’m having a fairly similar issue, did you ever get it solved? I believe it’s a linker error but in my case it looking for a file that I don’t think exists
@@gavinkujava6141 hey if your still having this issues delete remove "const" from main, eg. int main(int argc, char* argv[]) found it in the comments and it works
yeah I learned that the hard way i ended up crash my system after testing my game a few times and couldn't figure out why well it was because memory leaks
@This is God It doesn't allow it to be cross platform, that is just the definition of it's entry point. The function needs to have the same "signature" for the linker to be able to find it properly.
Can't get it to run. I get `INFO: Unable to initilize SDL: No available video device Game Cleaned. ` I'm on Ubuntu 18.04. tried installing a bunch of i386 packages, but no luck.
What's the point of the game class if it only gets one instance? Why not have pure functions handle the methods? (I haven't gone further than this video, so please excuse my ignorance of your future videos on this series)
Hi thanks for the turorial but I have 2 errors SDL_init is undefined and isRunning is undefined. I hope anyone can help me i am using visual studio 2019
+Seb B Hi Seb, it is a Mac. However because I'm using C++ and SDL2 the code is cross platform including Linux as well. All further episodes have/will been recorded in windows using visual studio 2017. Yes the Mac does seem to be on rise but windows still dominates the industry. Macs are a great machine fully capable and also can dual boot windows which makes it perfect for me.
Hey thanks for the reply! I have been programming on windows since 2004 when i got my first pc. Started programming in 1997. I've been programming a game using free pascal (using notepad++ and separately the free pascal compiler) and sdl 2 for about a year now. Yeah, i noticed that mac is used more and more. Songbringer and Axiom Verge were programmed on mac, i believe.
+Seb B No problems, Pascal?I have never really spent any time with with that. My first computer was an AST Win 95, can't remember it being as bad as its reputation. I came to programming around the same sort of time with Java and VB .Net. I Think I was around 17/18 when I moved to Linux and stayed there for a few years, it was then I started learning C++, then University for a game dev degree, which I went to windows then to a Mac and have never looked back. Best of both worlds :) Yes songbringer is done on Mac with Xcode using Cocos-2DX I believe.
Nice. I never studied programming. Been doing it daily as a hobby for 20 years. I taught myself everything. Most of what I learned was when the internet was not big like today, so did not have access to tutorials and updated compilers and IDEs. Don't know if that qualifies me for an actual programming job. I currently work in Accounts and the company relies on me to automate a lot of the tasks and finance processes for different teams (they are gaining a lot by paying me less than what it would cost them to outsource this). I use visual basic advanced and visual basic script in macros in excel. But I am also programming my own game (rpg about exploration and story, procedurally generated) in my free time, which I plan to sell one day.
Yeah I remember those days, We had Encarta on a Cd-Rom instead of Wikipedia, no google or UA-cam. It's more about experience than qualifications. How many projects you've shipped etc. Should ask for a raise ;). Yeah I love RPG's I was watching the songbringer devlogs which inspired me to make this series, hopefully it helps people. All you can do is keep at it, you will make it :)
A great tutorial but I have to ask shouldn't we add a delete game; bellow game->render(); in the main.cpp because if we don't the pointer won't be deleted and we will get a memory leak!!?
when program ends then all the memory allocated to the game will be cleaned automatically anyways, memory leak happens when you keep adding to the heap in a loop without freeing it, here we only do it once when we execute new() so to answer your question, no
Hi, im running on the currently newest version of XCode but no matter how much i try, i just dont get the cascade to work, i have my game.cpp, game.hpp and my main.cpp, even with all the includes, nothing is getting recognized (only got this with XCode, on VS19 there is no problem with recognizing the header)
I'd really like to use C# or Java (started with AS3) but the Garbage Collecting stuff is just triggering me so hard What kind of practice is it to create stuff and leave it around until someone else ends up picking it up.. It's like leaving plates in the kitchen until someone needing it cleans it up (deleting all references to it is like not leaving leftovers, it doesn't change much)
Fabian Roland there will be a video in the future on memory management, as it stands now when the program exit the os reclaims the memory anyway. I understand this is not best practice, but the code base has and will change a lot and this issues will be fixed.
in windows, the console only prints out "Game Cleaned" and exits out... (Press any key to continue) there is no window shown, anyone got a solution for that?
Hello ! I'm always getting LNK2019 unresolved external symbol SDL_main referenced in function main_utf8 Doing a project in school and really have to solve this . Thank you for Amazing tutorials either way
is there a list out there that contains all the absolute essential APIs? the complete list consists of thousands of functions(and methods) and i don't know where to look, I'm talking about methods like SDL_INIT_EVERYTHING and other basic APIs that one needs to create the skeleton of the game.
I can't use SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); I keep getting this output in XCode: Subsystems Initialized!... Window Created!... Renderer Created!... 2018-10-21 21:57:03.996549-0400 Game[3437:483097] MessageTracer: load_domain_whitelist_search_tree:73: Search tree file's format version number (0) is not supported 2018-10-21 21:57:03.996603-0400 Game[3437:483097] MessageTracer: Falling back to default whitelist Game Cleaned Program ended with exit code: 0
omg watching this vid made me ralize what the "->'' stands for when before I couldnt find an understandabe example because I am not from america or england. +1 like
Been stuck on an undefined member variable error for all the Game::functions() trying to get the window to render on Windows for the longest time. Code looks identical checking my one-liner g++ statement in case its the issue, which I used for a similar tutorial the other day... will post if I figure out my error :P Using VSCode What I'm currently working with: all: g++ -Isrc/include -Lsrc/lib -o main main.cpp -lmingw32 -lSDL2main -lSDL2
I ended up referencing both the header and the cpp file in my main.cpp. I'm still not sure why this was necessary. The tutorial did not require importing both, and despite game.cpp not being referenced game.h he only needs to reference game.h in his main.cpp. I understand that he may have a more complete IDE than VSCode and not a g++ makefile statement, but to me my solution seems off/lacking an understanding of my compiler, as I did somethign similar to make a previous tutorial work. Thanks for the tutorial and if anyone has insight on my lack of understanding feel free to comment
I am interested in the order of cleaning. Should we first destroy Renderer and then Windows instead of vice versa? After all, renderer has windows pointer...
why not just ... int main(){ Game game("Game",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,800,600,false); while(game.running()){ game.HandleEvents(); game.Update(); game.Render(); } } and instead of having separate functions init and clean just do that in the Constructor and Destructor
it's probably late but, i think it's bc of reusable code i mean in some cases you wanna call constructor and initialize some variables then in specific condition it will call the function and boom there is a window. Some times reusable code matters
In your Game::init() you're checking if SDL is properly initialised. Then you create a window and check that and a renderer. But you don't return Game::init() or create the renderer inside the if (window) block, so won't SDL_CreateRenderer() trip over a NULL pointer if SDL_CreateWindow() fails? Also if either SDL_CreateRenderer() or SDL_CreateWindow() fails you still set isRunning to true. This is why you should never do success handling but always do failure handling.
For Visual Studio Programmers, the biggest (and smallest) issue I had was giving me LNK issues.
The solution for me was in main.cpp. Remove the "const" type from "const char * argv[]" in the main function. It took way to long to figure this out, hope it helps someone.
You're a saint mate
Thank you
Bro you saved me a massive headache, thanks a lot!
Thank you!!! I had the same issue and this is exactly what I needed.
THANK YOU!!
You cannot imagine the satisfaction when the window started and everything was going correctly. Much Love
For the longest time I could not figure out how to separate SDL into a game engine without the entire project falling apart.
Thank you for helping me break through this barrier and into much more complex game designs!
Alec Dosier No problem :)
There are some issues with this code...
1) If SDL fails to create a window you don't want to then attempt to create a renderer.
2) Likewise if the renderer fails to initialize you don't want to set isRunning and start the update loop.
3) Because initialization can fail you should really be returning success/failure from this routine so that it can be handled appropriately.
Also a speed tip for those watching, after you have defined your class, just copy paste that into the cpp file. You don't need to type it all out again. You can replace the semi colons with open close braces and you are good to go, it will save you a tonne of time.
Finally a C++ tutorial that I understand something! Thanks!
Lucky
windows: in game header file add #define SDL_MAIN_HANDLED before including sdl.h
u r the man
omg i love u
you saved me, thank you so much
Wow thanks it worked!
Pain in the arse, what program doesn't have an int main(), why did they even think of this as a weird edge case.
Literally the first google search for "unresolved external symbol main", gives you a stack overflow article, and the second answer tells you about SDL_MAIN_HANDLED
I love these tutorials. It's slow enough that I can follow along but not slow enough to be boring or repetitive. Thank you.
For those compiling via g++ or make, the compilation command is "g++ -I src/include -L src/lib -o main.exe *.cpp -lmingw32 -lSDL2main -lSDL2"
epic gamer
If you also write -Wl,-subsystem,windows you can hide the console
im imagining someone finding this comment after trying to find the answer for hours and it working must be a wild feeling
Were you writing out the things you were going to do like; "While(game is running)" so then you can replace those with the code in the future? Genius!
thats psuedo codeing fran :D
It can be a good idea with complex projects to work out the structure or flow of how the program/game will work first.
@@ArkThaCreator stuff like this>>How you can tell people never took a proper class/ had anyone around them who writes code
@@boblee5556 Perhaps the person didn't take informatics classes or was simply not interested at that time in this topic. No need to be that harsh.
@@Kokurorokuko I really wasnt trying to be that harsh its just like we learned that in the mandatory CIS 101 for all students in freshmen year at my Junior college... its just hella easy to tell when people have never had any formal instruction... (protip, move to a state with socialized college, get wage-slave job to pay bills, wait one year to qualify as resident... profit)
Hi, just a question:
Why did you define the game variable in the global scope and not inside the main function itself?
Also why did you create it on the heap using new? And should it not because of that be explicitly removed using 'delete game' after the cleanup?
thanks in advance!
you know hes a real programmer when he start writing pseudo code straight into the ide
We must explain to the machine nicely before we decide to force it to do anything, just in case.
not rly actualy, tht just means he has created the code b4
real programmer would create a gui for a flowchart
@@Shootingstarsfizzy ui programmers pretending to be real programmers
Quick question. Why do you not just declare and implement the game class in the same file?
Nice! After learning some C++ essentials I was wondering what I would look for next, looks like this will do
All this at 21:40 does is create linker errors: LNK2019 unresolved external symbol SDL_SetRenderDrawColor referenced in function "public: void __cdecl Game::init(char const *,int,int,int,int,bool)" (?init@Game@@QEAAXPEBDHHHH_N@Z) is the first one...
Edit: make sure to watch the first video again in that case, I didn't add in linker - > input the dependencies... Also, there seems to be a naming conflict with the main function already being defined so somewhere so changing it to char* argv[] instead of const char* argv[] seems to fix that or you can #undef main in main.cpp... but I don't really understand so maybe it won't work for you :'(
btw, these codes work just as well on visual studio, right? or must something else be done in visual studio to make functional a game?
Thank you for the tutorial! The pace makes it easy to follow and understand.
This is awesome. I've been looking for a series like this that shows you how to build a game in Cpp without relying on a prebuilt engine. Good stuff!
19:05 what are you doing here? what is "Game *game"? because when I compile it gives me an error saying "game" was not defined in this scope even though I followed the tutorial to a T.
Thank you so much for the tutorial! After 3 hours of unsuccessful searches, I finally found what I was looking for! You are the best!
I do not know, and i hope anyone out their is needing this at this moment. Here it is, download SDL with Brew, I have no CLUE what it did but i downloaded all the libraries needed and it is working now. thank you for my ted talk
I started doing this in Visual Studio and straight from the start I'm confused about making a new source file; it only creates a "Name".cpp but no .hpp. It might be because of the IDE, but I'm not sure, it's my first time making a game...
Also, I've been following another tutorial but it only goes so far as creating a game window with a picture on it(I guess I made it using SDL libraries, but I'm unsure), nothing besides it, now I do know C++(I do not know SDL tho), and I have 0 clue of how to start making my game. Would you suggest I start from scratch following your tutorial or I could keep the other code? Here's the code if you're interested(ignore the comments, it's for me to understand what I did):
#include
#include
#include
const int WIDTH = 800, HEIGHT = 600;
//WIDTH i HEIGHT imaju dodeljene vrednosti koje predstavljaju
//sirinu i duzinu prozora
int main(int argc, char *argv[])//parametri su neophodni zbog SDL-a
{
SDL_Surface *imageSurface = NULL;
//kreiraju se SDL surface(povrsine)
SDL_Surface *windowSurface = NULL; //ovo ce biti povrsina prozora koji smo ovde kreairali(prozor je kao platno)
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) //ispituje se inicijalizacija svega u SDL-u
{
std::cout
to create a cpp as well as a hpp file at the same time create it as a class
Hey Ive only been programming in c# so far and you are using all that stuff in the game class like its static is that just by default in cpp or is there something behind that?
Glad to see that other programmers write flase instead of false.
lol
Thank you, this is great, I will definitely continue with the series. And I like how clean the main file is.
Thank you so much for your work. These videos are marvelous. If you don't mind a question though, I was following along with a different tutorial as well and they used "if( SDL_Init( SDL_INIT_VIDEO ) < 0 )" instead of "if (SDL_Init(SDL_INIT_EVERYTHING) == 0) {" and I was wondering if you have an opinion on this or not. For games is it simply just best to init everything all at once?
Thanks. This was a good start for me. I'm taking a data structures class next semester and so I decided to try to make a simple playing card game I made up as a way to brush up on my c++ and hopefully I will have a portfolio piece to add to my resume.
I'm using Eclipse in Kubuntu 22.04 and I was getting all the dreaded SDL undefined reference errors. I tried adding it to the linker and every other suggestion and finally deleted and purged both Eclipse and SDL2 and reinstalled both using the C++ version download from the Eclipse website. SDL I downloaded using apt and this series libsdl2-dev libsdl1.2-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev. Then I started a new Eclipse C++ and added SDL2 to the linker and path to the compiler includes. Now everything is working.
oof had my volume up all the way with earbuds in and.. that start sound... x....x
thanks for the tut ;D
For anyone on a Mac having trouble getting the window to show up, I found a post on SO that fixed the problem. Add this loop to your code instead of the SDL_Delay, and it will show up:
// A basic main loop to prevent blocking
bool is_running = true;
SDL_Event event;
while (is_running)
{
while (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT) {
is_running = false;
}
}
SDL_Delay(16);
}
finally a video where using namespace std isnt involved. thank you for sharing this, its been helpful
I’m new and curious why don’t u want to just declare it at the top so u don’t need to use std:: in everything ?
@@MrEvilyogurt "When C++ was originally designed, all of the identifiers in the C++ standard library (including std::cin and std::cout) were available to be used without the std:: prefix (they were part of the global namespace). However, this meant that any identifier in the standard library could potentially conflict with any name you picked for your own identifiers (also defined in the global namespace). Code that was working might suddenly have a naming conflict when you #included a new file from the standard library. Or worse, programs that would compile under one version of C++ might not compile under a future version of C++, as new identifiers introduced into the standard library could have a naming conflict with already written code. So C++ moved all of the functionality in the standard library into a namespace named “std” (short for standard)."
This basically means by putting using namespace std; at the top of your program subjects you to all the above issues stated with having standard library in your global namespace.
@@thedeagle1007 interesting thank you !
@@MrEvilyogurt No problem! I got that excerpt from the website I use to learn C++.
Learncpp.com.
It's free and has been quite helpful.
Thanks so much for this series! Love your pacing and information level ^^ hoping I can keep up through the whole tutorial. Just started with newest VC and SDL2 builds, everything working great so far. Cheers!
If your app crashes before it ever shows the window:
I was getting a crash before my window would load with an error like "library not loaded no suitable image found" for SDL2. And something else about a matching team ID
I fixed it by:
1. going to Project Settings > Build Settings > Other Liner Flags > Add "-framework SDL2"
2. going to Project Settings > Signing & Capabilities > Hardened Runtime > Check the box next to "Disable Library Validation"
3. in Project Settings > Signing & Capabilities > Signing > "Automatically manage signing" is checked, I have my personal account chosen for "Team", I have "Signing Certificate" set to "Sign to Run Locally"
Hopefully, after you set all these as described above, Clean, Build, and Run it will work.
Really enjoyed your first tutorial. I look forward to more to come.
Joel Quanbeck thank you :) next episode will tomorrow 21st
trying to follow along on VS. Having some frustrating bugs
Game.cpp(8,95): error C2761: 'void Game::init(const char *,int,int,int,int,bool)': redeclaration of member is not allowed
Game.cpp(9,1): error C2447: '{': missing function header (old-style formal list?)
I cant get it to run and cant figure out why, anyone know what's going on??
the second one is particularly frustrating bc the code mirrors the video
if you are getting unresolved external something on windows, remove "const" from main, eg. int main(int argc, char* argv[]), it helped me
Thank you :), how did you find this fix?
@@denizhandeniz5207 I'm find this fix here: stackoverflow.com/questions/31761045/sdl2-issue-undefined-reference-sdl-main
@@danieltietz4146 thnk u
For your error handling in the Init method couldn’t you use SDL_Log() and SDL_GetError()
eg. SDL_Log(“Unable to initialise SDL: %s”, SDL_GetError());
Instead of having to include iostream, or doesn’t it really effect performance that much?
Hey, it's been a while since I took time to continue your tutorial but I had an assignment in class where I had to work with SDL and classes. I took on the half finished tutorial I had made and it just works so well. I was able to add Physics components with physics and lateupdate I used the GameObject to manage the entity pointer and manager reference, I added an int for the layer in the map file... when I'll have more time I'll redo the whole tutorial from the beggining. I wondered though... my teachers insists on us using cpp files for logic and I noticed your components don't seem to use them and I was wondering if there was a reason why or if it was just a stylistic question.
I'm going to watch this everyday until I remember everything, then i'll practice and try on my first 2d rpg :)
so did u make it ?,
@@younlok1081 Doesn't seem like it
@@h-0058 lol maybe
No. The next day he probably said he was going to look at a Da Vinci painting every single day until he memorized the strokes, and then create his first rectangle house.
Hey its been 3 years did you make it
Hello, im getting a strange error when i try to compile. Variable 'Game::isRunning' is uninitialized aswell as renderer and window. i have been trying to find solution but cannot find anything.
Great tutorials. What happens if you call init() more than once? Shouldn't you check the window and renderer exist and destroy them before creating new ones? or would SDL handle that. Thanks.
Hello sire. Shouldn't the dealocation be done in the destructor? Making the clean () function unnecessary?
Yes, we can do that, but we will have to delete the game object explicitly at the end of main(). Game's Destructor function doesnt get called automatically when the program terminates.
Thank you so much for really concise and step by step API explanation of SDL. It really help me a lot! Subscribed and would watch for more!
Giri Prahasta Putra Thanks :)
I'm using codeblocks and get the following errors:
Game.cpp||In function 'void init(const char*, int, int, int, int, bool)':|error: 'window' was not declared in this scope|
Game.cpp|19|error: 'renderer' was not declared in this scope|
Game.cpp|24|error: 'isRunning' was not declared in this scope|
Game.cpp|27|error: 'isRunning' was not declared in this scope|
Game.cpp||In member function 'void Game::clean()':|
Game.cpp|53|error: 'SDL_QUIT' cannot be used as a function|
Any help would be appericiated
Fantastic tutorial. Easy to follow and straight to the point. Thanks!
If people are using visual studio and are still getting errors after trying all the different solutions, try putting #undef main under #include "Game.h" in the main file
Very very THX
thanks but can you tell me what type of project I need to do? (in visual studio)
you are a freaking genius!!! spent an hour trying to figure that out!!
@Der Absender I believe it's because the "SDL.h" header includes a header called "SDL_main.h" which has a declaration for the main function with the signature int main(int argc, char *argv[]). If you write a plain main definition as int main(), that puts a 2nd valid main function definition in the global scope. #undef main before YOUR main will remove the definition SDL has put in place and remove the ambiguity. Another way to solve it is to just declare main with the parameters (int argc, char *argv[]) to match the declaration SDL has. Hope this helps a week later.
in the Game.hpp file, you should set `bool isRunning=false` instead of just `bool isRunning` in order to avoid an infinite loop when Game is not initialized
Thank you so much! You saved my code.
What is the difference between using #pragma once vs using #ifndef, #define, #endif?
You don't need an init() function, you should be using the Game classes constructor, it is run automatically as soon as you create the Game object without any need to call init(). If you don't use a constructor, you may as well use C (which I actually prefer to be honest).
Neil Roy Hi Neil, it’s true that the game class could be initialised in the constructor, but I was in the mindset that doing it in an init function would allow me to reinitialise the game when I need it to be, not sure yet if I will be implementing restarts like this yet. I’ll be doing some sort of world/game manager at some point soon, so I’ll decide then. So yes it may end up in the constructor. For the use of c++ I will be using function templates and smart pointers later on in the series
Then call the function reset(). Requiring the class to be initialized after construction in order to make it operable is a violation of the RAII principle.
You throw an exception.
Would the same be true for clean() code actually belonging into the destructor?
@@Skandalos Yes that would be best practice. Same goes for the allocated game object, much better to just create a local game object, so we have better control over when it is destroyed.
Hi, thank you really much for your tutorial ! Is it normal that when i run the program, it takes about 40 seconds to initialize SDL2 ? (By that i mean nothing, not even "system initialized" appears on the console before these 40 seconds)
I am on Windows 10 using CodeBlocks ^^
+Fukiyel it should be quicker than that? Are there any logs you have access to?
Well i "corriged it" by removing the "if SDL_Init(SDL_INIT_EVERYTHING) == 0" check, i don't know why it was so slow to check for initialisation for me ._.
But well, it's normal now that it's removed, thanks anyway x')
why did you choose to allocate your game obj on the heap. Also you spent the time to free the SDL stuff in the destructor but then didn't even free the game obj itself?
Can't get this to build... I'm at 21:40, trying to get the window to show, but I get these messages:
main.cpp(4): error C2143: syntax error: missing ';' before '*'
main.cpp(4): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
main.cpp(8): error C2061: syntax error: identifier 'Game'
main.cpp(10): error C2065: 'SDL_WINDOWPOS_CENTERED': undeclared identifier
Other than the first line which says #include "Game.h" because I'm on windows, my code is exactly the same as in the video (or at least I don't see any discrepancies). Is there something else I need to do to make this work on windows? Using Visual Studio 2017 Community
Figured it out. For everyone running into this problem: I started this solution as a console application and Visual Studio needs me to #include "pch.h" in this situation. Took me all weekend to realize that I have to #include "pch.h" BEFORE #include "Game.h".
Such valuable info. So grateful. Thank you for the time you put into this tutorial.
The Error list says, that the "Game::isRunning", "Game::renderer" and the "Game::window" variables aren't initialised. "A Membervariable must always be initialised (type 6)."
Hey, I'm having an issue where every time I try to run the program I get an error saying that the application was unable to start (I'm on windows). Here's the full error code: The application was unable to start correctly (0xc000007b). Click ok to close the application. Any help would be much appreciated!
I am also having this error and am interested in any feedback
I got an error when creating a new game instance as a 'nullptr' (which is a keyword in C++11). So it wouldn't allow me to declare it as such.
So I just used the following instead and it worked fine:
Game *game = new Game();
Hope this helps.
Very nice tutorial, although a bit old and I have to say I had to resolve a few bugs here and there(no big deal, they were annoying tho), the very good thing about it is the fact that you organize everything so neatly... In other tutorials the code is just all in function main, wihtout any classes or managing code and it's all left to the viewer, along with all the issues that may come with organizing it all :P
Overall, thanks for this tutorial! :D
Really enjoying these videos. Will you eventually be capping the FPS or teaching us a time step method? Introduction of delta time?
GunnDawg There is a video on frame rate, and we will be using a ‘deltaTime’ system in the future. Just getting things done the simplest way then will be making things more robust as we progress with the engine and game.
shouldn't the game variable be deleted before closing the game? since it is on the heap
Really enjoying this series so far, great stuff!
I learn so much new things from you , you are a very good instructor thank you
Why do you use pointers? Why not just create the variable Game on the stack? Is there any benefit by it being on the heap?
Antonio Cs
I thought the same thing, not really as far as I can tell.
Doing this on visual studio. I've worked a lot with c#, so I'm thinking I can jump right into this! I was wrong... for anyone facing a wall of 200 errors right off the bat, try messing with your includes until that error number reaches zero. Good luck!
how did you get this to work in visual studio. i am very new to coding so im looking for all info about it i can get.
I watched the previous video on how to set up SDL on windows, and coming from that tutorial to this one, I have no idea what I’m supposed to do. I have to create a completely different project? What about all that set up I just did?
i think hat was just to lean how to put in sdl not specifically for this
The little Running() function in game class could be more aptly named GetIsRunning cause its essentially a getter.
Also the init function has the problem of still saying its running even if window and renderer return false,plus theres no debug message if those are false also But im nitpicking.Nice tutorial anyway.
I'm trying to get my code to work, but when I run it at the end of this lesson, I get an error window named '2D_GameEngine.exe' saying "The application was unable to start correctly (0xc000007b). Click OK to close the application." When I try to use breakpoints on the main function, it still spits out the error. Can someone help me?
Getting the same issue !
@@Nodal488 I was able to move past this problem, but I forgot what I did to fix the error. Oh I remember, I googled the error and found this page www.drivereasy.com/knowledge/how-to-fix-the-application-is-unable-to-start-correctly-0xc00007b-error/
I think I reinstalled the SDL2 package and it worked. I was using an external hard drive and had to move the downloaded files to get everything where it needed to be. After I reinstalled it was smooth sailing. Give that a try and let me know what you find!
Fixed ! Thanks !
Why in Game::handleEvents I always have error :
invalid use of member 'int Game::isRunning()' (did you forget the '&' ?)
How can I fix it ?
IDK about mac, but windows needs: int main(int argc, char * argv[]){} as opposed to int main(int argc, const char * argv[]){} .... this was giving me a headache trying to figure out why it kept telling me 'undefined reference to SDL_main'
you are my savior
@@alexanderthorbrugge6489 im glad this comment helped
Is it ok if I put a ternary operator for the fullscreen like so: (fullscreen) ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE
that would be my best guess yeah
i mean the flags variable is set for your flags which you can assign to functions
flags is initialized a value of 0
so instead of ''if (fullscreen)'' you could put other conditions like if (fullscreen == 1) {flags = SDL_WINDOW_FULLSCREEN;}
and have another condition such as (fullscreen == 2) { flags = SDL_WINDOW_RESIZABLE;}
You could rename ''fullscreen'' variable to ''screensize'' or something.
It would take some reworking the code but nothing too difficult
Why are we defining the Game class in a separate file? I don't understand the benefit to that. Also, my SDL header is not being recognized by my Game.cpp/Game.hpp files. I am using visual studio 2017 professional. Aside from this infuriating problem, I'm loving your work. I really appreciate what you are doing. Thank you.
It's an old standard for developers that worked before things like Git were in widespread use. I personally just put my implementation code in the header file. Much less file clutter. It's also a lot easier to edit than jumping back and forth through files just to change the name of a class's private data member's name.
try renaming the .hpp to .h
In visual studio 2019 Press Ctrl+. to trigger the Quick Actions and Refactorings menu and select Create Declaration / Definition from the context menu (quicker than typing)
I'm having trouble understanding why "new" was used for the Game object. Why does Game need to be on the heap?
cauz the instance is a pointer and we should allocate a space for im by using new
Thank you for the wonderful tutorial!
I ended up naming the Header with .h instead of .hpp.
I ended up getting an error "LNK2019" unresolved external symbol: "public: bool_cdecl"...
The pop-up error says, "Unable to run program...the system cannot find the file specified."
Any and all help with be deeply appreciated!
Thanks in advance,
C
I’m having a fairly similar issue, did you ever get it solved? I believe it’s a linker error but in my case it looking for a file that I don’t think exists
@@gavinkujava6141 hey if your still having this issues delete remove "const" from main, eg. int main(int argc, char* argv[]) found it in the comments and it works
you should call SDL_DestroyRederer before SDL_DestroyWindow on win7,otherwise sdl will throw exception.And thanks your video.
yeah I learned that the hard way i ended up crash my system after testing my game a few times and couldn't figure out why well it was because memory leaks
I've initialized The game on the Main.cpp file but while i am running the program it says that the game was cleaned.
check line 16
int main(int argc, char *args[])
if y'all having trouble.
omg I'm laughing here hahahahaha
It actually solved my LNK2019 problem and I don't get why. I'm pretty new to SDL and programming... Thanks a lot!
This allow SDL to be cross-platform
@This is God
It doesn't allow it to be cross platform, that is just the definition of it's entry point. The function needs to have the same "signature" for the linker to be able to find it properly.
when i used "const char" it was attempting to search for another function which broke the program.
Can't get it to run. I get `INFO: Unable to initilize SDL: No available video device
Game Cleaned. ` I'm on Ubuntu 18.04. tried installing a bunch of i386 packages, but no luck.
What's the point of the game class if it only gets one instance? Why not have pure functions handle the methods? (I haven't gone further than this video, so please excuse my ignorance of your future videos on this series)
just to make it look nicer i guess, usually there is player class as well to make only one player. That's just how oop works
Hi thanks for the turorial but I have 2 errors SDL_init is undefined and isRunning is undefined. I hope anyone can help me i am using visual studio 2019
Great video. Great speed and easy to follow along! Sub and going for the next vid! :) Keep up the great work!
Thanks :)
Is this a mac? why does everyone seem to be using mac to program games? i've always used windows.
+Seb B Hi Seb, it is a Mac. However because I'm using C++ and SDL2 the code is cross platform including Linux as well. All further episodes have/will been recorded in windows using visual studio 2017. Yes the Mac does seem to be on rise but windows still dominates the industry. Macs are a great machine fully capable and also can dual boot windows which makes it perfect for me.
Hey thanks for the reply! I have been programming on windows since 2004 when i got my first pc. Started programming in 1997. I've been programming a game using free pascal (using notepad++ and separately the free pascal compiler) and sdl 2 for about a year now. Yeah, i noticed that mac is used more and more. Songbringer and Axiom Verge were programmed on mac, i believe.
+Seb B No problems, Pascal?I have never really spent any time with with that. My first computer was an AST Win 95, can't remember it being as bad as its reputation. I came to programming around the same sort of time with Java and VB .Net. I Think I was around 17/18 when I moved to Linux and stayed there for a few years, it was then I started learning C++, then University for a game dev degree, which I went to windows then to a Mac and have never looked back. Best of both worlds :) Yes songbringer is done on Mac with Xcode using Cocos-2DX I believe.
Nice. I never studied programming. Been doing it daily as a hobby for 20 years. I taught myself everything. Most of what I learned was when the internet was not big like today, so did not have access to tutorials and updated compilers and IDEs. Don't know if that qualifies me for an actual programming job. I currently work in Accounts and the company relies on me to automate a lot of the tasks and finance processes for different teams (they are gaining a lot by paying me less than what it would cost them to outsource this). I use visual basic advanced and visual basic script in macros in excel. But I am also programming my own game (rpg about exploration and story, procedurally generated) in my free time, which I plan to sell one day.
Yeah I remember those days, We had Encarta on a Cd-Rom instead of Wikipedia, no google or UA-cam. It's more about experience than qualifications. How many projects you've shipped etc. Should ask for a raise ;). Yeah I love RPG's I was watching the songbringer devlogs which inspired me to make this series, hopefully it helps people. All you can do is keep at it, you will make it :)
A great tutorial but I have to ask shouldn't we add a delete game; bellow game->render(); in the main.cpp because if we don't the pointer won't be deleted and we will get a memory leak!!?
when program ends then all the memory allocated to the game will be cleaned automatically anyways, memory leak happens when you keep adding to the heap in a loop without freeing it, here we only do it once when we execute new() so to answer your question, no
Hi, im running on the currently newest version of XCode but no matter how much i try, i just dont get the cascade to work, i have my game.cpp, game.hpp and my main.cpp, even with all the includes, nothing is getting recognized (only got this with XCode, on VS19 there is no problem with recognizing the header)
I'd really like to use C# or Java (started with AS3) but the Garbage Collecting stuff is just triggering me so hard
What kind of practice is it to create stuff and leave it around until someone else ends up picking it up.. It's like leaving plates in the kitchen until someone needing it cleans it up (deleting all references to it is like not leaving leftovers, it doesn't change much)
Fabian Roland there will be a video in the future on memory management, as it stands now when the program exit the os reclaims the memory anyway. I understand this is not best practice, but the code base has and will change a lot and this issues will be fixed.
Thank you. You helped me a lot with my coursework! Very informative, this is exactly what I needed help with 👍 :D
lil tip for my windows friends select all in game.h, right click and click top option Create Definition
in windows, the console only prints out "Game Cleaned" and exits out... (Press any key to continue)
there is no window shown, anyone got a solution for that?
It says external symbol _SDL_main without solvin to what it references at in the function _main_utf8. Any ideas of how to solve it?
ever get this solved, well if you didnt and dont want to solve it im still going to tell you, change the solution platform to x64 instead of x86
Hello ! I'm always getting LNK2019 unresolved external symbol SDL_main referenced in function main_utf8
Doing a project in school and really have to solve this .
Thank you for Amazing tutorials either way
Edit - Just solved it .. changed constant char to just char in every file 😊
is there a list out there that contains all the absolute essential APIs? the complete list consists of thousands of functions(and methods) and i don't know where to look, I'm talking about methods like SDL_INIT_EVERYTHING and other basic APIs that one needs to create the skeleton of the game.
I can't use SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
I keep getting this output in XCode:
Subsystems Initialized!...
Window Created!...
Renderer Created!...
2018-10-21 21:57:03.996549-0400 Game[3437:483097] MessageTracer: load_domain_whitelist_search_tree:73: Search tree file's format version number (0) is not supported
2018-10-21 21:57:03.996603-0400 Game[3437:483097] MessageTracer: Falling back to default whitelist
Game Cleaned
Program ended with exit code: 0
omg watching this vid made me ralize what the "->'' stands for when before I couldnt find an understandabe example because I am not from america or england. +1 like
wehre u frorm
@@michaelerbaturakis2435 He's (or she's idk) from Bulgaria
Been stuck on an undefined member variable error for all the Game::functions() trying to get the window to render on Windows for the longest time. Code looks identical checking my one-liner g++ statement in case its the issue, which I used for a similar tutorial the other day... will post if I figure out my error :P Using VSCode
What I'm currently working with:
all:
g++ -Isrc/include -Lsrc/lib -o main main.cpp -lmingw32 -lSDL2main -lSDL2
I ended up referencing both the header and the cpp file in my main.cpp. I'm still not sure why this was necessary. The tutorial did not require importing both, and despite game.cpp not being referenced game.h he only needs to reference game.h in his main.cpp. I understand that he may have a more complete IDE than VSCode and not a g++ makefile statement, but to me my solution seems off/lacking an understanding of my compiler, as I did somethign similar to make a previous tutorial work. Thanks for the tutorial and if anyone has insight on my lack of understanding feel free to comment
I can't get the first stuff down #ifndef Game_hpp and #define Game_hpp I'm using windows..
Just needed an #endif/*Game_hpp*/ I'm good lol
you need to add the include library and use a syntax like this #include
I am interested in the order of cleaning. Should we first destroy Renderer and then Windows instead of vice versa? After all, renderer has windows pointer...
why not just ...
int main(){
Game game("Game",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,800,600,false);
while(game.running()){
game.HandleEvents();
game.Update();
game.Render();
}
}
and instead of having separate functions init and clean just do that in the Constructor and Destructor
it's probably late but, i think it's bc of reusable code i mean in some cases you wanna call constructor and initialize some variables then in specific condition it will call the function and boom there is a window. Some times reusable code matters
@@akira9449 ok , kind of makes sense ,
you could also pass the class "object" by reference as well
but i guess this method would be slightly easier.
just need to make sure you have it like
void somenewfunction(classname objectname){
//continue using the same "object" here
}
I'm getting Xcode and I'm gonna follow loads of tutorials
In your Game::init() you're checking if SDL is properly initialised. Then you create a window and check that and a renderer. But you don't return Game::init() or create the renderer inside the if (window) block, so won't SDL_CreateRenderer() trip over a NULL pointer if SDL_CreateWindow() fails? Also if either SDL_CreateRenderer() or SDL_CreateWindow() fails you still set isRunning to true. This is why you should never do success handling but always do failure handling.
Great job I hope this continues!
+Stan10785 Thanks ;) It will!
Is there a shortcut for Visual Studio that can Autofill SDL functions with default arguments?
Can you remake this video but in Windows please? It's really hard to follow you whilst you're using a different program than Visual Studio.