Xcode/TemplatesForXcode/SDL Application/main.c
changeset 2220 4d2d0548f5b2
parent 2213 59a667370c57
equal deleted inserted replaced
2219:f6099efa3f0b 2220:4d2d0548f5b2
     2 /* Simple program:  Create a blank window, wait for keypress, quit.
     2 /* Simple program:  Create a blank window, wait for keypress, quit.
     3 
     3 
     4    Please see the SDL documentation for details on using the SDL API:
     4    Please see the SDL documentation for details on using the SDL API:
     5    /Developer/Documentation/SDL/docs.html
     5    /Developer/Documentation/SDL/docs.html
     6 */
     6 */
     7 
     7    
     8 #include <stdio.h>
     8 #include <stdio.h>
     9 #include <stdlib.h>
     9 #include <stdlib.h>
    10 #include <string.h>
    10 #include <string.h>
    11 #include <math.h>
    11 #include <math.h>
    12 
    12 
    13 #include "SDL.h"
    13 #include "SDL.h"
    14 
    14 
    15 int
    15 int main(int argc, char *argv[])
    16 main(int argc, char *argv[])
       
    17 {
    16 {
    18     Uint32 initflags = SDL_INIT_VIDEO;  /* See documentation for details */
    17 	Uint32 initflags = SDL_INIT_VIDEO;  /* See documentation for details */
    19     SDL_Surface *screen;
    18 	SDL_Surface *screen;
    20     Uint8 video_bpp = 0;
    19 	Uint8  video_bpp = 0;
    21     Uint32 videoflags = SDL_SWSURFACE;
    20 	Uint32 videoflags = SDL_SWSURFACE;
    22     int done;
    21 	int    done;
    23     SDL_Event event;
    22         SDL_Event event;
    24 
    23 
    25     /* Initialize the SDL library */
    24 	/* Initialize the SDL library */
    26     if (SDL_Init(initflags) < 0) {
    25 	if ( SDL_Init(initflags) < 0 ) {
    27         fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    26 		fprintf(stderr, "Couldn't initialize SDL: %s\n",
    28         exit(1);
    27 			SDL_GetError());
    29     }
    28 		exit(1);
       
    29 	}
    30 
    30 
    31     /* Set 640x480 video mode */
    31 	/* Set 640x480 video mode */
    32     screen = SDL_SetVideoMode(640, 480, video_bpp, videoflags);
    32 	screen=SDL_SetVideoMode(640,480, video_bpp, videoflags);
    33     if (screen == NULL) {
    33         if (screen == NULL) {
    34         fprintf(stderr, "Couldn't set 640x480x%d video mode: %s\n",
    34 		fprintf(stderr, "Couldn't set 640x480x%d video mode: %s\n",
    35                 video_bpp, SDL_GetError());
    35                         video_bpp, SDL_GetError());
    36         SDL_Quit();
    36 		SDL_Quit();
    37         exit(2);
    37 		exit(2);
    38     }
    38 	}
    39 
    39 
    40     done = 0;
    40 	done = 0;
    41     while (!done) {
    41 	while ( !done ) {
    42 
    42 
    43         /* Check for events */
    43 		/* Check for events */
    44         while (SDL_PollEvent(&event)) {
    44 		while ( SDL_PollEvent(&event) ) {
    45             switch (event.type) {
    45 			switch (event.type) {
    46 
    46 
    47             case SDL_MOUSEMOTION:
    47 				case SDL_MOUSEMOTION:
    48                 break;
    48 					break;
    49             case SDL_MOUSEBUTTONDOWN:
    49 				case SDL_MOUSEBUTTONDOWN:
    50                 break;
    50 					break;
    51             case SDL_KEYDOWN:
    51 				case SDL_KEYDOWN:
    52                 /* Any keypress quits the app... */
    52 					/* Any keypress quits the app... */
    53             case SDL_QUIT:
    53 				case SDL_QUIT:
    54                 done = 1;
    54 					done = 1;
    55                 break;
    55 					break;
    56             default:
    56 				default:
    57                 break;
    57 					break;
    58             }
    58 			}
    59         }
    59 		}
    60     }
    60 	}
    61 
    61 	
    62     /* Clean up the SDL library */
    62 	/* Clean up the SDL library */
    63     SDL_Quit();
    63 	SDL_Quit();
    64     return (0);
    64 	return(0);
    65 }
    65 }