1 | // Example program:
|
---|
2 | // Using SDL2 to create an application window
|
---|
3 |
|
---|
4 | #include "SDL.h"
|
---|
5 | #include <stdio.h>
|
---|
6 |
|
---|
7 | int main(int argc, char* argv[]) {
|
---|
8 |
|
---|
9 | SDL_Window *window; // Declare a pointer
|
---|
10 | SDL_Renderer *s_ren;
|
---|
11 |
|
---|
12 | SDL_Init(SDL_INIT_VIDEO); // Initialize SDL2
|
---|
13 |
|
---|
14 | // Create an application window with the following settings:
|
---|
15 | window = SDL_CreateWindow(
|
---|
16 | "An SDL2 window", // window title
|
---|
17 | SDL_WINDOWPOS_UNDEFINED, // initial x position
|
---|
18 | SDL_WINDOWPOS_UNDEFINED, // initial y position
|
---|
19 | 640, // width, in pixels
|
---|
20 | 480, // height, in pixels
|
---|
21 | SDL_WINDOW_OPENGL // flags - see below
|
---|
22 | );
|
---|
23 |
|
---|
24 | // Check that the window was successfully made
|
---|
25 | if (window == NULL) {
|
---|
26 | // In the event that the window could not be made...
|
---|
27 | printf("Could not create window: %s\n", SDL_GetError());
|
---|
28 | return 1;
|
---|
29 | }
|
---|
30 |
|
---|
31 | // The window is open: enter program loop (see SDL_PollEvent)
|
---|
32 | s_ren = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE);
|
---|
33 | //s_ren = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
---|
34 | if (s_ren == NULL) {
|
---|
35 | printf("Could not create renderer: %s\n", SDL_GetError());
|
---|
36 | return 1;
|
---|
37 | }
|
---|
38 |
|
---|
39 |
|
---|
40 |
|
---|
41 | SDL_Delay(3000); // Pause execution for 3000 milliseconds, for example
|
---|
42 |
|
---|
43 | // Close and destroy the window
|
---|
44 | SDL_DestroyWindow(window);
|
---|
45 |
|
---|
46 | // Clean up
|
---|
47 | SDL_Quit();
|
---|
48 | return 0;
|
---|
49 | }
|
---|