comparison XCodeiPhoneOS/Template/SDL Application/main.c @ 2396:71edb7a747d7 gsoc2008_iphone

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