 Hello everybody and welcome back to the C++ SDL video tutorial series. In this video we're going to move on from the simple initialization program that we had in the last video, in the last tutorial, to something a little bit more, something that will actually do something. It'll still be very very basic and very very minimalistic, won't really do anything at all, but at least something will happen. We're going to create the basic window. Now let's hop on over to our documentation because that's what we're going to learn most of the things and remember that's online at libsdl.org. That's the SDL's library's homepage. You can find the documentation at wiki.libsdl.org. It's just the preceding term wiki. Okay we were looking at initialization and shutdown in the last tutorial. Now we're going to head back to that API by category, a little quick link over here and scrolling down from the basics. Now we want to look into video and we actually want to be able to display things. We can view information and functions related to display and window management. If we want to create a window, this is a pretty good place for us to start. Now this category contains functions for handling display and window actions. So we've got some stuff here we can do, we've got some structures, we've got functions and whoa! There's a function called SDL create window. I wonder what the heck that does. Let's go ahead and click on that, sorry and let's see what this does. This function will create a window with the specified position, dimensions and flags. Okay so it's got a specific syntax and it looks like it needs the type SDL window because that precedes the function call and it takes a pointer. All right it uses the asterisk and refers to this could very well be a pointer. Okay that's good to note. It takes a string or a constant character away for the title. I guess we can actually specify the title. It needs an x and a y coordinate as to where it will start on the screen. Oh and it takes some integers width and height. So we actually know x and y and width and height so we get to know how big the window will be and flags. It looks like okay it display it explains all this in the function parameters. The x position of the window can be a centered position. It looks like SDL has a flag for that or SDL window position undefined. This must be if the display manager will set the window wherever it wants to be all by itself. It lets the display manager handle that. Looks like there's another variable for that for SDL window position y in this case. We have the width of the window and the height of the window and zero or one or more SDL window flags that can be ordered together or use that pipeline like I mentioned in the last video. Return the window that was created or return null if it fails and you can use SDL to get error function for more information. Here are some examples. Okay cool they've got kind of the same code that we do. Okay it declares the pointer or the window variable is going to be containing this initializes SDL just like we had except we use everything rather than video and it creates this with all these arguments here. Window create window it uses it undefined and we'll probably do the same thing to start with and they're using the window open gl flag but we know we can use more than that and they actually test if the window could not go very well for us and then it will display nothing. It'll actually just tell us could not create the window. Let's do that in our code just to be safe and oh it uses SDL delay. I wonder what that does. It looks like the common here. It pauses execution for 3,000 milliseconds or just three seconds and then we'll destroy the window. Oh that must be a function pretty similar to SDL quits. It must clean up the memory out of location or whatever the case may be. Now it goes on to tell us that the flags may be any of the following or together. Oh we can set the window to be full screen. We can use resizable. Resizable is good. We should use that and okay open gl. I want to see what more that does. Window usable with open gl context. We probably won't need that. We do want some decorations though. Those are good options to know that exist though but I think the only one we'll actually want is window resizable in our case. Oh and destroy window. Let's check out what that does. Use this function to destroy window. Oh okay. Not much else there. Probably good practice to include at the very end of the program anyway though. So let's head back to that initial kind of example and let's base our code off of that. We can have an SDL window. Remember that's a pointer. I'll name the variable window. Let's declare that variable and now let's go ahead and set it to be something. Window can equal sdl underscore create window. Remember we're using that same naming convention for all the sdl functions the acronym underscore and the camel case function name and we want a title. I'm gonna throw in a shameless little plug here. Subscribe. And now we want the x and y coordinates. Well they're using sdl window position undefined so that that way the display manager can actually determine where it wants it to go and I'll do the same thing for my code here and I'm actually just gonna kind of layer these so it's a bit more readable and my screen doesn't have to go all that far. Now we want the window width. I'll say 400. Just put a comment here window width and 200 comment here window height. Okay cool. And for the flag let's go sdl window underscore. I believe that's how it's formalized. Yep sdl underscore window underscore resizable underscore resizable. Cool. That's good. That's good for us. And now we can now that that's displayed. We do want to remove it or delete it. So let's go sdl destroy window. I think we just pass in a window. Check it out in the example again. That does just take window there. Okay and they're using display. Sorry delay to be able to see it. Let's do the same thing. Remember to end all of your lines with a semicolon. We'll use 3000 just as well. In fact let's go 5000. So you have those many milliseconds and let's test if the window is equal to null. Then we should display something the screen. So let's actually go ahead and include iostream. We're gonna using C plus plus typical output method output stream. There was an error initializing. Initialating initializing. Okay I've completely butchered this word initializing. There we go. The window. Let's include an end line. And let's go ahead and include sdl get error. Because that was the function that they mentioned would return anything bad. Let's go ahead and search what that actually does just so we know sdl underscore get error sdl underscore get error. Search for this. Okay cool. We get right to the page. Use this function retrieve a message about the last error that occurred. Well I don't really see this happening too often and just in case we do see an error. But let's test if we get a problem just by including that. Okay good. I believe our code is just about fine now. Let's help over to the terminal try and compile this. Right now the file is still called initialization.cpp. I'm gonna go ahead and rename this. I'll use it 01. I'll call it 01 basic window.cpp. And just for housekeeping sake I'm gonna go back to the initialization function and remove all this code. Now I'll go back to basic window. Okay cool. Now I'll hop over to the terminal c++ or g++ 01 basic window.cpp and remember to compile with c++ we use our backticks package config cflags and libs for the library sdl2. Run this. No errors. Awesome. Now let's run this eight on out and whoa I got a small little window here. You can see it says subscribe that's the window title and it displayed for five seconds and you could just see that it was it removed it destroyed the window right after those five seconds. I can move this around just a black box very very simple but if I do nothing it'll close out of it. Cool. We can of course change this to be anything we really want. We can have a delay for only one second. Now if I run this code I'm gonna compile it run the code one second and boom it's gone. One second again and it's gone. So that's how the sdl delay function will work. It just simply delays the processing for however many milliseconds you'd like and the create window function will create a window destroy window destroys it and you have a specific amount of flags that you could use also window position undefined window position centered. It's a good idea to take a look at the documentation so you can really see what's going on and what other options you have for your create window function. Cool. Thank you guys for watching this video. Hope you enjoyed this and be sure to look at the documentation and see what more cool stuff you can do. See you in the next tutorial.