Kohi #001: Game Engine Setup for WINDOWS (Vulkan Game Engine Series)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everybody and welcome to the second video in the kohi game engine series where we are building a game engine from scratch using vulcan nc so in this video i want to go ahead and get us set up to run on windows we are going to be tackling windows and linux but i figure i'm going to tackle windows first and then we'll go ahead and scaffold on linux and then we'll just sort of go back and forth between the two until we have both platforms complete so before i begin i would like to give a shout out to the channel's first partner the partner is the highest tier of membership on the channel and that partner is a arslia i hope i pronounced that correct thank you very much for supporting the channel i would also like to give a quick thank you to the other supporters of the channel who are up on the screen now thank you very much your support is greatly appreciated if you would like to support the channel you can do so by clicking the join button down below details on memberships are actually available in the video i will post here there will also be a link in the description below so first off i've created a folder here on my c drive and i'm going to be putting everything in kohi in this kohi folder and then i've got a code folder which is actually going to hold my repository so i'm just going to select the bar here and type cmd just to get a command prompt window to open in that folder and i'm going to say git clone and i'm going to take this web address here the github.com slash travis vermin koki and paste that in there and now that is going to clone into kohi so i'm going to get out of this command prompt i don't need it anymore for now okay and one thing i'm actually going to do is i don't need this extra folder so i'm actually going to take this and move it up a level and delete this just so that i don't have multiple layers of folders here okay so now that we have that cloned we actually need to go ahead and grab our compiler now if you guys do not have clang installed you will want to go to llvm.org builds and you will want to grab this windows installer link that is right here i will include a link to this in the description below but it's honestly a pretty short url we want the windows snapshot build that was from the 28th of august 2020. this is the most recent version of clang that was built sort of as a snapshot for windows so you want to grab this installer package and go ahead and run through that install since i already have this installed on my machine i just want to bring something up as you're running through the install process you want to make sure to add the llvm to the system path for all users you want to make sure that this is selected because if you don't you won't be able to actually run clang from the command prompt so as you're running through the setup process make sure that you go ahead and select that option so the other thing i want to point out is if you do not have vs code installed you can get it from code.visualstudio.com download and uh this is the editor that we're going to be using so i already have this installed i don't need to do this so something else that i wanted to point out that we're also going to need is we're going to need the vulcan sdk to actually develop against vulcan so to get this you'll go to lunergy.com vulcan sdk and you go to the bottom of the page here and click where it says download the vulkan sdk and you want to click the windows icon here and then you'll want to go ahead and just grab whatever is the latest version of vulcan here under the under the windows sort of section here so that that would be in this case the vulcan sdk 1.2 162 blah blah installer exe so you want to download and install that just the default options on that are fine after you're done with that to make sure that everything that we have installed so far is correct we just want to run a couple things in our command window so the first thing that we want to do is we want to echo and then we want this percent symbol and then in all uppercase vulcan underscore sdk and then another percent symbol so this is a environment variable that basically says we want to echo whatever is in this and so when we do that you should get a path to somewhere in your computer typically it'll be vulcan sdk 1.2 148 whatever now my version of vulcan is obviously a little bit older than the newest one released here but these minor versions don't matter quite as much as the major ones so what's most important is that we're on some version of 1.2 okay so we'll want to make sure that the vulcan sdk is installed correctly you'll also want to test to make sure that clang is installed correctly just by typing clang and you should get this thing that says clang error no input files that's fine it just means that clang is installed and ready for us to use so let me go ahead and get rid of this browser and i'm going to right click in this code folder i created earlier and say open with code and here is my code window and i do want to take a moment just to point out some of the extensions i have installed now i have quite a few installed here but only a couple of them actually apply to this series so the first one is this c c plus plus plugin we definitely want to make sure that that is installed because we'll be using that heavily i like this to do highlight this is a plug-in that highlights to-do text in a various color in in your code so that you can actually see it so it stands out a little bit better and i'm also using the groov box themes the the dark hard theme that is in here so you'll want to go ahead and at least at the very minimum install this cc plus extension the others are optional but this one's super important also this shader languages support one is pretty important as well so the very first thing we're going to want to do is create a new folder and we're going to call it engine under that we're going to create another new folder and call it source under the engine folder we're going to create a new file and we're going to call it build.bat and i'm not going to run through all of this in great detail because explaining batch files isn't exactly the point of the series i'm just going to paste some code that i've written here ahead of time again this is all going to be available on the repository so this is our build script for the engine library that we talked about before so basically what it does is it gets a list of all the c files and then feeds a bunch of arguments to a command down here to clang so this is where we actually call clang we pass the list of file names we pass our comp our compiler flags we want g to export debug information and we want shared which says basically create a dll and then these other ones i'll come back to later they're not really all that important right now but just make sure that they're there and then our include flags we're basically saying include the source directory and include the vulkan sdk directory which we'll come back to that in a bit the linker flags we want to link with user32 vulcanone and we want to include the vulcan sdk library again i'll come back to this vulcan sdk thing in a bit so our defines we want to define underscore debug something called k export and dcrt secure no warnings i'll come back to these later once we actually need them okay and so uh the next thing here is our assembly we're calling engine this is basically what the file name is going to be called when we write this out so we just do a quick echo here of that saying that we're building it and then we call clang and we pass all these things here now this also outputs to a bin folder which we do not have yet and then it outputs a assembly.dll file so just be aware of that is what is all this all this stuff is doing here okay so now that we have that in our source folder we want to go ahead and create a new file and we're going to call this defines.h okay and this is going to include some basic type information that we're going to need to know so again i am actually going to paste in some code here and just sort of explain it so we are basically type defining some various types of data here so we're wanting to use these shorter names because we don't want to be typing unsigned care or unsigned short or unsigned long we'd much rather just reference them by how many bits they are so we have u8 for unsigned character which is just an 8-bit integer 16-bit 32-bit 64-bit so we have unsigned then we have signed then we have our floating point types which are going to be our f-32 32-bit float and 64-bit float and then we're going to have boolean types we have a 32-bit boolean and a 8-bit boolean and i'll get into why we need those later we also are going to do some static assertion on those data types which basically make sure that for the platform we are building on that these types are the size that we expect so this static assertion basically says hey is the size of a u8 one byte is the size of u16 two bytes etc and so we just verify those using this static assert macro the static assert macro basically behaves differently for playing in gcc than it might for other compilers so i want to be sure to use the correct underlying type there we also define true and false and then we also have some of our platform detection code here and i'm not going to go into all of this right here because this is quite a lot of of platform detection as you can tell but uh basically the gist of it is if it's windows then we define windows um and then if for some reason we're not building 64-bit we throw an error message saying hey we're only supporting 64-bit if we are on linux or some form of gnu linux then we say our platform uh is linux by defining the platform linux we also have some android support in here as well as unix which is sort of a catch-all in case something is not caught by these and then down here we actually have some apple platform detection i'm not going to go into that right now but it's there just in case we need it in the future and then finally we have some things here for exporting and importing functions so basically when you build a dll you need to export any any function that you want available for use and anything referencing that we want to basically say in this case deco spec export and you'll note that this is not actually set up yet because we haven't set this up yet we'll get to that in the future or here in a few moments but we basically want to use this flag in front of functions to export it so we'll come back to this in a bit but just be aware that this is here and i'll come back and um and you guys will see how we're going to use that when we get to that point okay so now that we have our build script and a basic file to build something against i actually want to take a moment and do some of our vs code setup so we need to create a new folder called vs code and if you guys aren't using vs code you can actually skip this step but otherwise you're going to need it so within here we want to create a new file and this is going to be called c underscore cpp underscore properties dot json and again i'm just going to paste some code in here because this setup isn't 100 necessary to explain at least at this point but i'll go over it quickly so we have two configurations in here i went ahead and pasted in the linux one as well but the one we're concerned with right now is win32 so this is going to be the windows setup which basically says our include path is the uh sort of the same thing that we defined here in our build.bat where we said we want the source folder and the include folder uh we need to define this again here so that the intellisense or the code completion can actually pick up on it and then we have some defines here which is where we actually define our debug we have some unicode defines here but then we also have this k export defined here and i'll come back to that in a second we do make use of this windows sdk version um we may or may not need to actually do this but for now um this helps us with our auto completion our compiler path is basically where llvm actually wound up getting installed so you'll need to find out where this clang exe file is on your hard drive and point to that location here we are using the c standard c17 we also have the cpp standard defined here as well just in case we ever need that for some reason and we set the intellisense mode to clang x 64. now you'll note that the linux version looks almost identical so this will just sort of help us to skip this step of having to redefine this stuff when we actually get to the linux side of it it'll make that side a little quicker so with both of these things in here this is basically our you could think of it as our intellisense configuration for this project for each one of these platforms so the next file i'm going to put in here in the vs code folder is something called extensions.json and this is simply a list of recommended extensions so the extensions that i pointed out to you in here will actually be in here so when you guys actually clone this and open this up this will recommend these for you and you can go ahead and install them that way it sort of just automates that for you so i'll put that in there for you guys to make it a little easier next i'm going to paste in the key bindings that i use in this keyboundings.json file this does actually not have any effect on the configuration of vs code as it is but what you want to do is you want to copy all of these entries in here and then in nvs code you want to hit f1 and then type keyboard and it'll give you this open keyboard shortcuts json and you'll want to place your your guys's file will probably be empty probably looks something like that and you'll just want to take everything that is within these brackets in this file here and go ahead and paste that in your keybindings json file that is in your user folder and then you guys will be using the same key bindings that i'm using okay so again not super important stuff but i figured i should cover it anyway what is a bit important is another file we're going to create which is called launch.json and again i'm going to paste in my configuration that i have here so i have a windows launch and a linux launch i'm not going to cover the linux launch right now but you guys can probably figure out how that works basically all this is going to do is say the type of debugger that we want to use when we're going to go ahead and debug our project so in the windows 1 we want cpp vs debug and then the request type is launch the program is going to be the workspace folder slash bin testbed.exe we're not going to pass any arguments we're not going to stop at the entry we are going to set the current working directory to the workspace folder bin and then the environment we're not going to pass any environment variables for now and the console is going to use a new external window that basically means that just pops up a new command prompt window that we are going to be echoing a lot of our logging to okay and then obviously we'll come back to this this linux one here but it's almost the same thing it's just the paths are a little bit different in linux format instead okay all right so we are actually almost done here we want one more actually we want two more files so we want a settings json file and again this is going to be a configuration that i use you guys don't necessarily have to stick with this you can remove properties as you want but if you want the same setup that i have visually here on the screen this is the configuration for that i'm actually not going to walk through this because it's mostly pretty explanatory as to what's going on here so this will be automatically cloned for you guys just so you know what this is this is very various settings that are at the project level if you guys want to tweak that you're more than welcome to finally we have one more file in here which is called tasks.json and this is where our build tasks actually exist so uh we actually have a we have three tasks we have one to build the engine one to build our test bed which we haven't set up yet and then one to build everything and they're mostly the same basically the only difference is what batch file they call right so in this case we have a windows for windows we call build.bat for linux we'll set up something called build.sh and then it just sets the current working directory uh and that's about it right just says you know that's the build task so when we use the build keyboard shortcut it'll kick off one of these things or give us the option so we have one for engine one for testbed which is almost exactly the same just with the updated paths and then we have one for building everything which basically calls this build all batch file that we'll create here in a moment that calls both of these things okay so with that said that is all the vs code setup we'll go ahead now and set up our test bed so to do that in the base folder here we're going to create a new folder i'm going to call it testbed we'll add another folder to that called source and to the testbed folder we are going to add a new file and we're going to call this build.bat and again i'm just going to paste some code in here this is almost exactly the same as the engine one except this one is going to be to build the test bed so the only difference here is the name of the assembly that that outputs we are not building it as a shared assembly we do not have to link with all the things that the dll has to link with that's one of the reasons that we do it with a dll and i will get more into that explanation as time continues um but we do have to link with the l engine.lib so when we build it i'll point out what that means but for now just understand uh that's what we're doing okay and again we just call clang using the file names compiler flags um and in this case we build excel assembly.exe because we want an executable and then everything else is the same so i hope that's pretty self-explanatory if you guys want more details on that feel free to leave a comment below okay so the last build script we want to set up is actually in the root folder so in the root folder i want to add new file and we're going to call this buildal.bat and buildal.bat is actually remarkably simple so it just simply says we're building everything and then it pushes the directory so it's basically says switch to this directory which is the engine so it goes into this engine folder calls build.bat and then pops back out of the directory and then this line here basically says if the build process returned anything other than zero then we want to actually abort this script so if the build failed with errors for some reason it's not actually going to try and build testbed if we failed on engine it'll just it'll just fail the entire script and a board out and so basically does the exact same thing for testbed which would prevent it from saying all assemblies built successfully if it fails and that is really all there is to that okay so we need a couple of things code wise to actually test our setup here so one thing i want to do is in our engine source we want to create a new file and we're going to call this test.h so the first thing we'll say is pragma once and then in here we will go ahead and we're just going to create a simple function to make sure that our our function exports work so so the first thing we'll need to do is include defines.h and then we'll say kapi and we'll just call this print underscore int right not something nice and simple and this will be it'll take an i32 and we'll just call it i right and that's it we just want to test that we can actually call a method from our our engine dll from the the testbed application right and so all this is going to do is simply print something out so let's go ahead and the source and we will create a another new file and we'll call this test.c and in test.c we will whoops i just realized i forgot void there we need we still do need void because we're not returning anything in our test.c we need to include test.h and we have our print function we are also going to need to include stdio.h okay and we're just going to do a simple call to printf to say the number is and then percent i for an integer and then whatever we pass right and so this is just a quick test um i know i'm sort of glossing over a lot of things here but it's not really relevant to the initial project setup i will go back and explain how all these things work in the future i just want you guys to sort of see how we're setting up the project and then we'll jump into the details okay so we have our test.c or test.h so the next thing we want to do is uh down here in our testbed source we want to create a new file and we want to call this main.c right and this is where the entry point for our application will be right now this will eventually be changing but for right now this is where we want that to be so we need to include test.h now note that i've done this in between angle brackets instead of quotes because we are not including it a test.h locally out of here we're actually including it out of engine.source so it's i figured it's very important to actually point that out and the next thing is our actual entry point itself will be a int name and it's not going to take any arguments whatsoever so i'll just leave void there and we are going to call our function here that we exported our print int function right so we can say print int and we'll pass it and we'll pass a 42. 42 is a good number and return zero turn 0 simply means success right so this should be everything that we need i believe to actually go ahead and build our project so let's go ahead and press ctrl shift b and it looks like we have an error here cannot find bin engine dll okay so i'm guessing oh okay so that is because it's saying it cannot open file bin engine dll and the reason is is because we don't actually have a bin folder so we'll need to create that so um in the base folder here we'll say new folder bin and then ctrl shift b again okay and it built successfully so if we expand this bin folder we'll see that we have all kinds of stuff in here so i just want to take a minute to explain sort of at least the important files some of these aren't important but some of them are so at least on windows we have our engine dll which is our engine library that i mentioned before right so this is the actual thing that we've built we also have an engine.lib which is sort of a import library that is actually triggered by if we look at defines.h and we have this decal spec dll export that is actually what triggers this lib file to be created ordinarily when you build a dll you don't get one of these but by using deco spec dll export that's what we get right and i've just defined this here as k api so in our test dot h where we said k api we're basically saying we want to export this function for use in other libraries or executables okay and then we also have an engine.pdb this file is what where the actual debug information for the dll file exists so if we were to actually step through this code to debug this which i'll show you guys in a second that is actually what the debugger needs to know about this dll in order to actually perform that so the next thing we have here is our testbed.exe and we have our testbed.pdb so our exe obviously is is the executable that we've built and then the testbed pdb is the debug information for the testbed executable and so it's output everything here to the bin folder which makes it nice and easy to work with and so if we look here in our main.c i'm actually going to set a breakpoint right here on line four and i'll do that just by sort of clicking over here in the gutter where this this uh red dot shows up and i'll go ahead and press f5 and now we are looking at our debugger so we get this window this command console window that that pops up for me it pops up on the other screen but um for those of you who are only working with one monitor it'll just pop up probably right over top of your vs code window and you'll notice that there's nothing written to it yet and that is because we have actually stopped the execution of the application at line four um in main.c because we set a breakpoint here so this little yellow thing here in the highlighted line shows us where we are currently waiting to execute the next line of code okay and so this is next going to call our print int from our test.h that is in our our dll file right so we're in our main.c which is the executable the executable is now going to call the dll so we continue into that or we step into that rather by either clicking this step into button or pressing f11 which i actually prefer so press f11 and you'll see that it brings us here to the print int function that is present in our dll so if i press f11 one more time we step into that function and if we hover over i we see that it is in fact 42 which is what we passed from our executable so the next thing i'm going to do here is call printf which is a function that allows us to print text to the console and this is basically going to print out the number is and then whatever the number is so i'm going to press f10 to actually step over that which means i don't want to step into and debug printf because i don't really care how it works under the hood i just want to step over that so i'm going to press f10 and then i'm actually going to select my console window again and you'll see here that it has actually printed out the number is 42. so we know that things are working so i'm going to go ahead and continue the application which is going to finish the execution because we have actually finished executing this and we'll see down here at the bottom that the program testbed exe has exited with code 0 which is a success so this is the basic project setup for windows there's not a whole lot to it but you know the idea here is to keep things relatively simple and so now what we'll do is we'll go ahead and step over to the linux side of things in the next video and we will perform the same linux setup on that side and i'll walk you guys through that so so if you guys like the video feel free to go ahead and hit the like button if you haven't already consider subscribing hit the little bell notification there to get notifications when the next video in the series drops and i will see you guys next time [Music] you
Info
Channel: Travis Vroman
Views: 6,515
Rating: undefined out of 5
Keywords: write a game engine, write your own game engine, make a game engine, how to write a game engine, learn to write a game engine, writing a game engine, make your own game engine, game development, game dev, game engine, game developer, how to, tutorial, programming, gamedev, vulkan game engine, vulkan, game engine series, how to make a game engine, vulkan api, 3d game engine, vulkan engine, vulkan tutorial, 3d graphics, learn vulkan, 3d vulkan, how to vulkan, vulkan renderer
Id: F6_WdnzQIQ4
Channel Id: undefined
Length: 30min 3sec (1803 seconds)
Published: Fri Mar 12 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.