|
@@ -4,70 +4,70 @@
|
|
|
|
|
|
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] 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.2] Anticipate quit
|
|
|
+ atexit(SDL_Quit);
|
|
|
|
|
|
- // [1.3] Set title
|
|
|
- SDL_WM_SetCaption("Application SDL", 0);
|
|
|
+ // [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] 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
|
|
|
+ // [2.2] Other components
|
|
|
SDL_Surface* grass = SDL_LoadBMP("textures/grass.bmp");
|
|
|
|
|
|
- /// [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] 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
|
|
|
+ // [3.2] Compute
|
|
|
// Nothing for now
|
|
|
|
|
|
- // [3.3] Draw phase
|
|
|
- SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 255, 255));
|
|
|
+ // [3.3] Draw phase
|
|
|
+ SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 255, 255));
|
|
|
|
|
|
SDL_BlitSurface(grass, 0x0, screen, 0x0);
|
|
|
|
|
|
- SDL_Flip(screen);
|
|
|
+ SDL_Flip(screen);
|
|
|
|
|
|
SDL_Delay(16);
|
|
|
- } // end of main loop
|
|
|
+ } // end of main loop
|
|
|
|
|
|
- ///[4] Free components
|
|
|
+ ///[4] Free components
|
|
|
SDL_FreeSurface(grass);
|
|
|
|
|
|
- SDL_FreeSurface(screen);
|
|
|
+ SDL_FreeSurface(screen);
|
|
|
|
|
|
- std::cout << "No error caught." << std::endl;
|
|
|
- return 0;
|
|
|
+ std::cout << "No error caught." << std::endl;
|
|
|
+ return 0;
|
|
|
}
|