Mercurial > sdl-ios-xcode
comparison XCodeiPhoneOS/Demos/src/rectangles.c @ 2385:0705e8ebe951 gsoc2008_iphone
Rectangles demo (SDL_RenderFill)
author | Holmes Futrell <hfutrell@umail.ucsb.edu> |
---|---|
date | Fri, 18 Jul 2008 20:52:18 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2384:6a946f3155d8 | 2385:0705e8ebe951 |
---|---|
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 #include "common.h" | |
10 | |
11 void render(void) { | |
12 | |
13 Uint8 r, g, b; | |
14 /* Come up with a random rectangle */ | |
15 SDL_Rect rect; | |
16 rect.w = randomInt(64, 128); | |
17 rect.h = randomInt(64, 128); | |
18 rect.x = randomInt(0, SCREEN_WIDTH); | |
19 rect.y = randomInt(0, SCREEN_HEIGHT); | |
20 | |
21 /* Come up with a random color */ | |
22 r = randomInt(50, 255); | |
23 g = randomInt(50, 255); | |
24 b = randomInt(50, 255); | |
25 | |
26 /* Fill the rectangle in the color */ | |
27 SDL_RenderFill(r, g, b, 255, &rect); | |
28 | |
29 /* update screen */ | |
30 SDL_RenderPresent(); | |
31 | |
32 } | |
33 | |
34 int main(int argc, char *argv[]) { | |
35 | |
36 SDL_WindowID windowID; | |
37 int done; | |
38 SDL_Event event; | |
39 | |
40 /* initialize SDL */ | |
41 if (SDL_Init(SDL_INIT_VIDEO) < 0) { | |
42 fatalError("Could not initialize SDL"); | |
43 } | |
44 | |
45 /* seed random number generator */ | |
46 srand(time(NULL)); | |
47 | |
48 /* create window and renderer */ | |
49 windowID = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); | |
50 if (windowID == 0) { | |
51 fatalError("Could not initialize Window"); | |
52 } | |
53 if (SDL_CreateRenderer(windowID, -1, 0) != 0) { | |
54 fatalError("Could not create renderer"); | |
55 } | |
56 | |
57 /* Fill screen with black */ | |
58 SDL_RenderFill(0,0,0,0, NULL); | |
59 | |
60 /* Enter render loop, waiting for user to quit */ | |
61 done = 0; | |
62 while(!done) { | |
63 while (SDL_PollEvent(&event)) { | |
64 if (event.type == SDL_QUIT) { | |
65 done = 1; | |
66 } | |
67 } | |
68 render(); | |
69 SDL_Delay(1); | |
70 } | |
71 | |
72 /* shutdown SDL */ | |
73 SDL_Quit(); | |
74 | |
75 return 0; | |
76 } |