annotate XCodeiPhoneOS/Template/SDL Application/main.c @ 2468:cbcd2e990cfc gsoc2008_iphone

removed build folder from branch
author Holmes Futrell <hfutrell@umail.ucsb.edu>
date Mon, 18 Aug 2008 20:15:24 +0000
parents 71edb7a747d7
children
rev   line source
2396
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
1 /*
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
2 * rectangles.c
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
3 * written by Holmes Futrell
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
4 * use however you want
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
5 */
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
6
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
7 #include "SDL.h"
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
8 #include <time.h>
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
9
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
10 #define SCREEN_WIDTH 320
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
11 #define SCREEN_HEIGHT 480
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
12
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
13 int randomInt(int min, int max) {
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
14 return min + rand() % (max - min + 1);
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
15 }
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
16
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
17 void render(void) {
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
18
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
19 Uint8 r, g, b;
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
20 /* Come up with a random rectangle */
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
21 SDL_Rect rect;
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
22 rect.w = randomInt(64, 128);
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
23 rect.h = randomInt(64, 128);
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
24 rect.x = randomInt(0, SCREEN_WIDTH);
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
25 rect.y = randomInt(0, SCREEN_HEIGHT);
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
26
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
27 /* Come up with a random color */
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
28 r = randomInt(50, 255);
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
29 g = randomInt(50, 255);
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
30 b = randomInt(50, 255);
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
31
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
32 /* Fill the rectangle in the color */
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
33 SDL_RenderFill(r, g, b, 255, &rect);
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
34
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
35 /* update screen */
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
36 SDL_RenderPresent();
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
37
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
38 }
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
39
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
40 int main(int argc, char *argv[]) {
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
41
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
42 SDL_WindowID windowID;
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
43 int done;
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
44 SDL_Event event;
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
45
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
46 /* initialize SDL */
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
47 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
48 printf("Could not initialize SDL\n");
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
49 }
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
50
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
51 /* seed random number generator */
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
52 srand(time(NULL));
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
53
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
54 /* create window and renderer */
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
55 windowID = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL|SDL_WINDOW_SHOWN);
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
56 if (windowID == 0) {
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
57 printf("Could not initialize Window\n");
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
58 }
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
59 if (SDL_CreateRenderer(windowID, -1, 0) != 0) {
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
60 printf("Could not create renderer\n");
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
61 }
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
62
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
63 /* Fill screen with black */
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
64 SDL_RenderFill(0,0,0,0, NULL);
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
65
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
66 /* Enter render loop, waiting for user to quit */
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
67 done = 0;
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
68 while(!done) {
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
69 while (SDL_PollEvent(&event)) {
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
70 if (event.type == SDL_QUIT) {
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
71 done = 1;
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
72 }
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
73 }
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
74 render();
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
75 SDL_Delay(1);
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
76 }
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
77
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
78 /* shutdown SDL */
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
79 SDL_Quit();
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
80
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
81 return 0;
71edb7a747d7 XCode template for iPhone SDL projects
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff changeset
82 }