Tille - I can see you, read those man pages!   Tille's Site

Full screen mode

For going full screen, we have to enable some other form of quitting the program, such as pressing the Escape key, instead of only checking the upper right corner of the assigned window. Both changes are done in the main function:

int main()
{
  SDL_Surface *screen;
                                                                                
  if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
        fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
        exit(1);
  }
  atexit(SDL_Quit);
                                                                                
  screen = SDL_SetVideoMode(640, 480, 16, SDL_FULLSCREEN|SDL_HWSURFACE);
    if ( screen == NULL ) {
        fprintf(stderr, "Unable to set 640x480 video: %s\n", SDL_GetError());
        exit(1);
    }
                                                                                
  printf("Set window of 640x480 at %d bits per pixel mode\n",
        screen->format->BitsPerPixel);
                                                                                
/* Set random seed. */
  srandom(time (0));
                                                                                
  SDL_Event event;
                                                                                
  int quit = 0;
  while ( !quit ) {
                                                                                
  MyEffect(screen);

/* Keep an eye on the keyboard and mouse. */
    while (SDL_PollEvent ( &event )) {
                                                                                
                switch( event.type ){
                case SDL_QUIT:
                        printf("Received Close Window request.\n");
                        quit = 1;
                        break;
                case SDL_KEYDOWN:
                if ( event.key.keysym.sym == SDLK_ESCAPE ) {
                        printf("Received Esc.\n");
                        quit = 1;
                        }
                        break;
                    default:
                        break;
                }
                                                                                
            }
                                                                                
    }
                                                                                
  printf("Quitting SDL.\n");
                                                                                
  return(0);
}

Exercise: supplementary enable the Q key to quit; check with sdldocs Handling the Keyboard. Don't show the mouse pointer (see libsdl.org SDL_ShowCursor).

Click here for the solution.

Home
© 1995-2010 Machtelt Garrels - tille - Powered by vIm - Best viewed with your eyes - Validated by W3C - Last update 20100511