Vulkan API Tutorial - 5 - Window

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone and welcome to this Vulkan API tutorial this time finally we are going to create a window it's unfortunately it's not going to be too much of use for now it's obviously required a step but we will not be able to render to the window until later I will also include xcb linux files with their github source and I have to thank you mikail for actually helping me out with it with this I don't have Linux installed currently and I'm not too familiar with Linux but hopefully you guys will get the source that will run just fine with Windows and Linux included in this tutorial we'll discuss the window creation on Windows I'm not going to go into too much detail about how we actually go into what are the commands for windows because this is a Vulcan tutorial not Windows tutorials so the actual costs operating system I'm gonna be real quick about those and you can check the source code after it's made available in the github the link is in their description of the video I do have to say that if you can you can use GE lfw but I'm gonna do the operating system specific functions for these tutorials because there's actually a few details that I want to show you and those are kind of hidden away in that GL fw okay so before we actually start let's clean up our code a little bit let's delete all this command buffer stuff that we made in the previous tutorial we do not need it Volken should only be debarked when we are developing the program so I'm gonna make a new header I'm gonna call it build options all caps in this case let's make that a hitter in this file there will be a few options on a few defines build underscore enable walking debug and then the value on top of that or give it a value and another one build enable Vulcan runtime debug and give it a one as well okay this file then changing this to 0 or 1 enables or disables Vulcan debugging so let's go through the or prendre rotor CPP again and let's include that file now all of this are the see here now in here we can just add a preprocessor directive so if build an a poll Vulcan debug let's up else and in deep in here ok now that's gonna leave all of this debug code out when we actually building the Vulcan without debugging that leaves a few functions for us hanging like in its Deepak T in its Deepak so I like to do it like this I'd rather have the free processor directives outside of functions of our if I can't then I can just create empty functions in case we're not using the debugging and now this should work let's see if it does let's set up the built-in april vulcan deepak to zero let's run it okay seems to be running just fine so let's move forward now the build enable vulcan runtime teapot this one is going to be an apple in the shared dot cpp if build enable vulcan runtime debug is enable who are going to run this function otherwise we cannot run this empty function of this one like so and let's copy this function over here there we go and of course we need to include the file or the header in this file okay moving on so the next thing i want to actually create is another header and this one will be a platform header platform okay this header is basically responsible for choosing our operating system I'm using Windows and I want to use windows native window manager for all of window creation I also plan to use xcb libraries on Linux to create a window so native windows and native Linux windows and this header basically just includes windows or xeb libraries or whatever we need also Volken this should be their only file that includes walkin and if any parts of my program needs a Vulcan library they should include this file instead that is basically just to guarantee the ordering of includes and other things but anyway let's get started if win32 and win32 is defined actually not if but if death if we have to find windows 32 which is always true on windows or even on the 64-bit windows in that case we're using windows else error platform not yet supported closing this off with and if so if we if we are using windows let's include windows windows dark edge okay on the last line will include Vulcan I also will add the linux native windows through xeb library but I'll add that off-screen anyway all the Linux users users should get most of this tutorial out so anyways one difference is for Linux though is that you need to actually connect to the x11 server first but that'll be apparent in the code later on okay I'm cleaning up a little bit more in the renderer dot cpp after the build options include I want to include the platform and then I can just remove this line of code if def we need to include windows that age I also want to do the same in the header files like renderer renderer dot H do not include Vulcan directly let's include it via the platform edge like this also let's remove this include Vulcan in the shed dot H file let's include the platform that should be basically all about this and now we can actually start creating our windows or window glass I'm going to do this the easy way around and I'm gonna create a glass for a child glass for the renderer so let's add a dots this is a little bit annoying that sometimes microsoft visual studio wants to tell me that some objects already exists even though it doesn't exist for this project so going manually again that's a little bit annoying and i wouldn't really mind if that feature went away if the headers i mean that if the files for this glass does not exist why should you care anyways a little bit of run there let's create our window dot age header file the window dot CPP file let's create our class like so now that we have our window glass we can actually start including it in the renderer so to keep this tutorial simple I'm gonna make it possible only to have one window at a time it should be relatively easy to create more windows using this with small code changes but there's a lot more to it later on so I'm just gonna stick with one window so let's actually create a pointer to a window and this window is not included by default obviously this is a header file so I don't want to include the whole window header in this file instead I'm just gonna do the classical window defining the window or introducing the window within this rendered row header and the next step would be to create a few functions we obviously need to create the window somehow so I'm gonna make a function that returns a pointer to this window that we create we have a small problem in here because create window is a windows function that actually creates a window on windows it would be just fine but this is actually a macro to define macro so we need to use something else let's just call it open the window they should work obviously if you're not using Windows and you don't want to port this over to Windows then you don't need to worry about this open window would take three parameters for now sighs X sighs why and name think I'm like the sizes to be you int32 integers like this and I also want to create the main loop at this point in the program I'm actually going to do it as Italy engine did I'm going to create a function that returns a boolean value and the function name will be simply just run takes no parameters and for as long as this run function returns true that's how long the program or application should run it's also going to update the whole renderer class at the same time let's create these two functions okay so on the run function I'm gonna return true for now and on the open window function I'm going to create a new window and I'm gonna store it in the window pointer so underscore window is new window also anything with the window class in this file and then I'll just simply return it so like this okay let's go back to the window class and start building that class up within this window class we are going to create a couple of functions the first one would be closed so avoid hello this would close the window when an object want to destroy itself it gets a little bit trickier but basically what this does is it's going to notify the renderer that we want to close a window and we do that via the updates function so I'm gonna create a new function here and call it update it cannot return a boolean value with this building value that's returned by this function is going to just tell should we still keep running this window or not so I just want to flag this somehow and create a small boolean it flag for this like this I'm gonna create these functions and in these functions if I just call closed function all I want to do is to set this one boolean that we have in here window should run to false and all the update I just want to return this like this okay this is all well and good and easy but I want to first go through with this so we can have a solid base where we can actually start building the windows now if we go to the renderer dot cpp and let's go to the function run in here if we have a window then we occurrence a return window update so this is all well and good and this should be relatively easy for you but on the next step we actually want to create the windows themselves so let's create a private function or private method and I'm gonna call this in it OS window the second one function I want is again what function D in it always window that's basically going to destroy the window third one will be update or West window and final one will be in it OS surface so these four functions are going to be cold but I'm actually not going to create these functions within this window dot CPP file I want to create a new file for this and this is just basically to keep it more simple or to develop on multiple platforms so what I'm gonna call this new file will be window underscore win32 and if you're working on Linux you could use like X he be in here but anyway continuing the tutorial now so in this new file I'm gonna include the window file or header since this is not exactly a tutorial about windows I'm just gonna copy pasted all this code in here and I'm gonna briefly go through it all but for now don't worry about that too much no way to make this multi-platform I'm going to include also include platform and build options now in this platform file or platform header we need to somehow tell that we are indeed using Windows and there's actually a really good option in here that we could use so if def we knit 32 let's also define a VK use platform win32 khr when we define this and then include vulcan that causes the vulcan header to intrude introduce some new functions for us so if we go to this header file and let's see where it is here we can use platform win32 khr it's gonna include a bunch of things also a couple of functions VK create win32 a surface for example so that's how you get this function by defining this macro here and also going to define it as one because that makes our life a little bit easier and going back to the window underscore win32 CPP we can just use this macro to define or determine if we are indeed using Windows like so we also need a few things in the windows sorry window header so window dot H we also need these functions in here I'm not going to go Institute much detail but basically instance window class name and class ID counter so let's start with a he needs OS window on Windows I should also include assert by the way well we still need to give the window size to this class and windows or window name but Ella let's discuss this a little bit first so we in 32 instance class name and class ID counter instance and window handle are kind of self-explanatory class name is something that's specific to windows it basically need a unique name for each window so to make this easy to create multiple windows I can use a Windows class ID counter that's basically going to add a number after the window name and that should make sure that our window class name is always unique and then just incrementing that that's all basically what this does so is initialize window glass the class structure and register that class try it if it's registered if nas was dropouts define the style that's basically the default style no maximizing the window are not resizing the window creating the window here and this is a bit odd in Windows you set window a long pointer to this class structure and use as a user datum show window set foreground window that's basically bringing his fronds and setfocus let's focus on that window easy function stay in it's always window destroy window and now the unregister the class that we created finally updates a windows sorry update OS window I'm not just gonna handle the messages that we sent to the MIT window that's basically all about it one more thing is that as a adjust window rekt he X function in here on Linux this doesn't seem to apply but on Windows when you introduced your windows size that's going to count in if I just show it to you so on Windows at least if you create a window like this you can't do areas basically the window size in Windows includes the header what we want is actually the surface area which is the internal actual area way we can actually draw so this function only make sure that we convert the size of the window we increase it a little bit so we can actually get the surface size that we want now that's about all I'm gonna tell you about this well there's a Windows event handler this is basically how you handle events and as a when we set the long pointer this gets that long pointer and the user dates are basically which is reinterpret traits it's back to windows or handle to windows or window glass and then we can just call window close and that's basically how you close the window ok yeah let's go back to the window don't H file what I wanted to hear is you 32 T surface size X by default I'm gonna say it's have 512 and the same thing for the surface size why and lastly the name you're not hiding up at the Bissell little kids going back to the constructor now so let's actually initialize our window create the windows or OS a specific window and on the destructor we cannot destroy that window and finally let's go to the main dot cpp and in here i want to create the main loop and the window so our open window let's give it a size 800 x 600 because why not I'm just a quick name and then I want to create the main loop which is basically a while elope while or run now if it tries to run this now I think nothing is actually going to happen because I forgot one thing well let's try it I'll try it anyway yeah we got unresponsive window so what I did forget is actually when we opened the window or create the window in the renderer dot cpp we actually need to need to give the window size and the name to this constructor so let's do that like this and let's copy this over to the actual function in here like this now let's see it should be the right size with a right name this time or it fails well I seem right I forget a lot of things today ok now it should work yeah that works a lot better it has the right name it has the right size still unresponsive because we still haven't put them updates in the run a loop so in the window update function when we actually update we also need to call the update Oh where's window and now it should become responsive because we're sending because we're sending signals to this window and it responds to those signals so this worked just fine okay let's try closing this so when I hit X yeah I did close the program when we call the close function so it should put the window should run boolean C false and on the renderer which is can return that boolean from the window update function and that means in our main function in the loop it's going to return false to this while loop which makes the program end and the default destructor off the renderer class should destroy all of our resources which by the way does not destroy our window yet so before we forget let's go there and let's handle this so in the in the destructor of the renderer delete window okay should be a lot better now yep okay I think this is all for this time and the source will be with the Linux windows in the github I'll see you soon and the next time we'll actually discuss the surface the surface will be a little bit shorter one so I think I'll might include something else in that video as well anyway till next time
Info
Channel: Niko Kauppi
Views: 16,255
Rating: undefined out of 5
Keywords: vulkan, api, tutorial, specification, graphics, programming, gpu, graphics card, c++, cpp, code, coding, advanced, close to metal, glnext, window, operating system, native window
Id: J87M6HdcjS0
Channel Id: undefined
Length: 29min 37sec (1777 seconds)
Published: Tue Apr 12 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.