Mercurial > sdl-ios-xcode
annotate Xcode-iPhoneOS/Template/SDL iOS Application/main.c @ 5284:96a22141cf86 tip
Changed output directory of Universal libSDL.a for iOS to respect build configurations. Template generator was updated to reflect these changes as well.
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Sat, 12 Feb 2011 21:52:30 -0800 |
parents | 067973aec4d8 |
children |
rev | line source |
---|---|
5077
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1 /* |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2 * rectangles.c |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3 * written by Holmes Futrell |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4 * use however you want |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5 */ |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6 |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7 #include "SDL.h" |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
8 #include <time.h> |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
9 |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
10 #define SCREEN_WIDTH 320 |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
11 #define SCREEN_HEIGHT 480 |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
12 |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
13 int |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
14 randomInt(int min, int max) |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
15 { |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
16 return min + rand() % (max - min + 1); |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
17 } |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
18 |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
19 void |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
20 render(void) |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
21 { |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
22 |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
23 Uint8 r, g, b; |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
24 /* Come up with a random rectangle */ |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
25 SDL_Rect rect; |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
26 rect.w = randomInt(64, 128); |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
27 rect.h = randomInt(64, 128); |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
28 rect.x = randomInt(0, SCREEN_WIDTH); |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
29 rect.y = randomInt(0, SCREEN_HEIGHT); |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
30 |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
31 /* Come up with a random color */ |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
32 r = randomInt(50, 255); |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
33 g = randomInt(50, 255); |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
34 b = randomInt(50, 255); |
5078
067973aec4d8
iOS Xcode project template fixes/changes.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
5077
diff
changeset
|
35 SDL_SetRenderDrawColor(r, g, b, 255); |
5077
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
36 |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
37 /* Fill the rectangle in the color */ |
5078
067973aec4d8
iOS Xcode project template fixes/changes.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
5077
diff
changeset
|
38 SDL_RenderFillRect(&rect); |
5077
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
39 |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
40 /* update screen */ |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
41 SDL_RenderPresent(); |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
42 |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
43 } |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
44 |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
45 int |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
46 main(int argc, char *argv[]) |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
47 { |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
48 |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
49 SDL_WindowID windowID; |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
50 int done; |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
51 SDL_Event event; |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
52 |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
53 /* initialize SDL */ |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
54 if (SDL_Init(SDL_INIT_VIDEO) < 0) { |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
55 printf("Could not initialize SDL\n"); |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
56 } |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
57 |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
58 /* seed random number generator */ |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
59 srand(time(NULL)); |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
60 |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
61 /* create window and renderer */ |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
62 windowID = |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
63 SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
64 SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN); |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
65 if (windowID == 0) { |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
66 printf("Could not initialize Window\n"); |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
67 } |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
68 if (SDL_CreateRenderer(windowID, -1, 0) != 0) { |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
69 printf("Could not create renderer\n"); |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
70 } |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
71 |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
72 /* Fill screen with black */ |
5078
067973aec4d8
iOS Xcode project template fixes/changes.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
5077
diff
changeset
|
73 SDL_RenderClear(); |
5077
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
74 |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
75 /* Enter render loop, waiting for user to quit */ |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
76 done = 0; |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
77 while (!done) { |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
78 while (SDL_PollEvent(&event)) { |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
79 if (event.type == SDL_QUIT) { |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
80 done = 1; |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
81 } |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
82 } |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
83 render(); |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
84 SDL_Delay(1); |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
85 } |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
86 |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
87 /* shutdown SDL */ |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
88 SDL_Quit(); |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
89 |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
90 return 0; |
37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
91 } |