comparison Xcode-iPhoneOS/Demos/src/rectangles.c @ 3277:20326ba2bda2

This name inconsistency has been bugging me for a while...
author Sam Lantinga <slouken@libsdl.org>
date Sat, 19 Sep 2009 07:32:36 +0000
parents
children 64ce267332c6
comparison
equal deleted inserted replaced
3276:720d176be107 3277:20326ba2bda2
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
12 render(void)
13 {
14
15 Uint8 r, g, b;
16 /* Come up with a random rectangle */
17 SDL_Rect rect;
18 rect.w = randomInt(64, 128);
19 rect.h = randomInt(64, 128);
20 rect.x = randomInt(0, SCREEN_WIDTH);
21 rect.y = randomInt(0, SCREEN_HEIGHT);
22
23 /* Come up with a random color */
24 r = randomInt(50, 255);
25 g = randomInt(50, 255);
26 b = randomInt(50, 255);
27
28 /* Fill the rectangle in the color */
29 SDL_SetRenderDrawColor(r, g, b, 255);
30 SDL_RenderFill(&rect);
31
32 /* update screen */
33 SDL_RenderPresent();
34
35 }
36
37 int
38 main(int argc, char *argv[])
39 {
40
41 SDL_WindowID windowID;
42 int done;
43 SDL_Event event;
44
45 /* initialize SDL */
46 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
47 fatalError("Could not initialize SDL");
48 }
49
50 /* seed random number generator */
51 srand(time(NULL));
52
53 /* create window and renderer */
54 windowID =
55 SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
56 SDL_WINDOW_SHOWN);
57 if (windowID == 0) {
58 fatalError("Could not initialize Window");
59 }
60 if (SDL_CreateRenderer(windowID, -1, 0) != 0) {
61 fatalError("Could not create renderer");
62 }
63
64 /* Fill screen with black */
65 SDL_SetRenderDrawColor(0, 0, 0, 255);
66 SDL_RenderFill(NULL);
67
68 /* Enter render loop, waiting for user to quit */
69 done = 0;
70 while (!done) {
71 while (SDL_PollEvent(&event)) {
72 if (event.type == SDL_QUIT) {
73 done = 1;
74 }
75 }
76 render();
77 SDL_Delay(1);
78 }
79
80 /* shutdown SDL */
81 SDL_Quit();
82
83 return 0;
84 }