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