-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreatewindow.cpp
More file actions
executable file
·39 lines (30 loc) · 1.21 KB
/
createwindow.cpp
File metadata and controls
executable file
·39 lines (30 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Using SDL2 to create an application window
#include <SDL2/SDL.h>
#include <iostream>
int main(int argc, char* argv[]){
SDL_Init(SDL_INIT_VIDEO); // Initialize SDL2
SDL_Window *window; // Declare a pointer to an SDL_Window
// Create an application window with the following settings:
window = SDL_CreateWindow(
"An SDL2 window", // const char* title
SDL_WINDOWPOS_UNDEFINED, // int x: initial x position
SDL_WINDOWPOS_UNDEFINED, // int y: initial y position
640, // int w: width, in pixels
480, // int h: height, in pixels
SDL_WINDOW_SHOWN // Uint32 flags: window options, see docs
);
// Check that the window was successfully made
if(window==NULL){
// In the event that the window could not be made...
std::cout << "Could not create window: " << SDL_GetError() << '\n';
SDL_Quit();
return 1;
}
// The window is open: enter program loop (see SDL_PollEvent)
SDL_Delay(3000); // Wait for 3000 milliseconds, for example
// Close and destroy the window
SDL_DestroyWindow(window);
// Clean up SDL2 and exit the program
SDL_Quit();
return 0;
}