myapp.cpp 1.1 KB

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