Mercurial > sdlxcode4templates
annotate SDLApplicationBase.xctemplate/main.c @ 0:b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
the two is SDLMain.
Copy all templates to
~/Library/Developer/Xcode/Templates/SDL
or
/Library/Developer/Xcode/Templates/SDL
Templates based off information documented here:
http://blog.boreal-kiss.net/2011/03/11/a-minimal-project-template-for-xcode-4/
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Sun, 02 Oct 2011 21:14:53 -0700 |
parents | |
children |
rev | line source |
---|---|
0
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1 |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2 /* Simple program: Create a blank window, wait for keypress, quit. |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3 |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4 Please see the SDL documentation for details on using the SDL API: |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5 /Developer/Documentation/SDL/docs.html |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6 */ |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7 |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
8 #include <stdio.h> |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
9 #include <stdlib.h> |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
10 #include <string.h> |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
11 #include <math.h> |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
12 |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
13 #include "SDL.h" |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
14 |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
15 int main(int argc, char *argv[]) |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
16 { |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
17 Uint32 initflags = SDL_INIT_VIDEO; /* See documentation for details */ |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
18 SDL_Surface *screen; |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
19 Uint8 video_bpp = 0; |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
20 Uint32 videoflags = SDL_SWSURFACE; |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
21 int done; |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
22 SDL_Event event; |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
23 |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
24 /* Initialize the SDL library */ |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
25 if ( SDL_Init(initflags) < 0 ) { |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
26 fprintf(stderr, "Couldn't initialize SDL: %s\n", |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
27 SDL_GetError()); |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
28 exit(1); |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
29 } |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
30 |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
31 /* Set 640x480 video mode */ |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
32 screen=SDL_SetVideoMode(640,480, video_bpp, videoflags); |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
33 if (screen == NULL) { |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
34 fprintf(stderr, "Couldn't set 640x480x%d video mode: %s\n", |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
35 video_bpp, SDL_GetError()); |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
36 SDL_Quit(); |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
37 exit(2); |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
38 } |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
39 |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
40 done = 0; |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
41 while ( !done ) { |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
42 |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
43 /* Check for events */ |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
44 while ( SDL_PollEvent(&event) ) { |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
45 switch (event.type) { |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
46 |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
47 case SDL_MOUSEMOTION: |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
48 break; |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
49 case SDL_MOUSEBUTTONDOWN: |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
50 break; |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
51 case SDL_KEYDOWN: |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
52 /* Any keypress quits the app... */ |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
53 case SDL_QUIT: |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
54 done = 1; |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
55 break; |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
56 default: |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
57 break; |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
58 } |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
59 } |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
60 } |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
61 |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
62 /* Clean up the SDL library */ |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
63 SDL_Quit(); |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
64 return(0); |
b0b91cadc484
Initial Xcode 4 templates for SDL/Mac 1.2 and 1.3. The major difference between
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
65 } |