Mercurial > sdl-ios-xcode
annotate Xcode-iPhoneOS/Template/SDL iOS Application/main.c @ 5077:37b582b8bb07
New iOS Xcode target to build libSDL.a and lipo Simulator & Device binaries together.
New iOS Xcode target to prepare an Xcode template using the Universal libSDL.a.
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Mon, 31 Jan 2011 00:37:38 -0800 |
parents | |
children | 067973aec4d8 |
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); |
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
|
35 |
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 /* Fill the rectangle in the 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
|
37 SDL_RenderFill(r, g, b, 255, &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
|
38 |
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 /* 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
|
40 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
|
41 |
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 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
|
45 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
|
46 { |
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 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
|
49 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
|
50 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
|
51 |
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 /* 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
|
53 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
|
54 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
|
55 } |
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 /* 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
|
58 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
|
59 |
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 /* 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 } |
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 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
|
68 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
|
69 } |
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 /* Fill screen with black */ |
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 SDL_RenderFill(0, 0, 0, 0, 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
|
73 |
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 /* 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 } |
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 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
|
83 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
|
84 } |
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 /* 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
|
87 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
|
88 |
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 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
|
90 } |