1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- // Author : Jovian HERSEMEULE
- #include <iostream>
- #include <SDL/SDL.h>
- int main()
- {
- /// [1] Start
- // [1.1] Start SDL
- if ( SDL_Init( SDL_INIT_VIDEO ) < 0)
- {
- std::cout << "Can't initialize SDL: " << SDL_GetError() << std::endl;
- return 1;
- }
- // [1.2] Anticipate quit
- atexit(SDL_Quit);
- // [1.3] Set title
- SDL_WM_SetCaption("Application SDL", 0);
- /// [2] Create components
- // [2.1] Create window
- SDL_Surface* screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
- if ( !screen )
- {
- std::cout << "Unable to set 640x480 video: " << SDL_GetError() << std::endl;
- return 1;
- }
- // [2.2] Other components
- // Nothing for now
- /// [3] Main loop
- bool done(false);
- while (!done)
- {
- // [3.1] Events
- SDL_Event event;
- while (SDL_PollEvent(&event))
- {
- switch (event.type)
- {
- case SDL_QUIT:
- done = true;
- break;
- case SDL_KEYDOWN:
- if (event.key.keysym.sym == SDLK_ESCAPE)
- done = true;
- break;
- } // end switch event type
- } // end of message processing
- // [3.2] Compute
- // Nothing for now
- // [3.3] Draw phase
- SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 255, 255));
- // other draws
- SDL_Flip(screen);
- SDL_Delay(16);
- } // end of main loop
- ///[4] Free components
- SDL_FreeSurface(screen);
- std::cout << "No error caught." << std::endl;
- return 0;
- }
|