Debian Codegraph @

manual tests/4 standalone binaries/myapp.cpp

raw
1 #include<SDL.h>
2 #include<memory>
3 #include<iostream>
4 #include<string>
5
6 int main(void) {
7 SDL_Surface *screenSurface;
8 SDL_Event e;
9 int keepGoing = 1;
10 std::string message;
11
12 if(SDL_Init( SDL_INIT_VIDEO ) < 0) {
13 printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
14 }
15 atexit(SDL_Quit);
16
17 std::unique_ptr<SDL_Window, void(*)(SDL_Window*)> window(SDL_CreateWindow( "My application", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN), SDL_DestroyWindow);
18 screenSurface = SDL_GetWindowSurface(window.get());
19
20 // Use iostream to make sure we have not screwed
21 // up libstdc++ linking.
22 message = "Window created.";
23 message += " Starting main loop.";
24 std::cout << message << std::endl;
25
26 while(keepGoing) {
27 while(SDL_PollEvent(&e) != 0) {
28 if(e.type == SDL_QUIT) {
29 keepGoing = 0;
30 break;
31 }
32 }
33 SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0x00, 0x00));
34 SDL_UpdateWindowSurface(window.get());
35 SDL_Delay(100);
36 }
37
38 return 0;
39 }