comparison Xcode-iPhoneOS/Template/SDL Application/main.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 b6c7a6b07ebf
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
10 #define SCREEN_WIDTH 320
11 #define SCREEN_HEIGHT 480
12
13 int
14 randomInt(int min, int max)
15 {
16 return min + rand() % (max - min + 1);
17 }
18
19 void
20 render(void)
21 {
22
23 Uint8 r, g, b;
24 /* Come up with a random rectangle */
25 SDL_Rect rect;
26 rect.w = randomInt(64, 128);
27 rect.h = randomInt(64, 128);
28 rect.x = randomInt(0, SCREEN_WIDTH);
29 rect.y = randomInt(0, SCREEN_HEIGHT);
30
31 /* Come up with a random color */
32 r = randomInt(50, 255);
33 g = randomInt(50, 255);
34 b = randomInt(50, 255);
35
36 /* Fill the rectangle in the color */
37 SDL_RenderFill(r, g, b, 255, &rect);
38
39 /* update screen */
40 SDL_RenderPresent();
41
42 }
43
44 int
45 main(int argc, char *argv[])
46 {
47
48 SDL_WindowID windowID;
49 int done;
50 SDL_Event event;
51
52 /* initialize SDL */
53 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
54 printf("Could not initialize SDL\n");
55 }
56
57 /* seed random number generator */
58 srand(time(NULL));
59
60 /* create window and renderer */
61 windowID =
62 SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
63 SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
64 if (windowID == 0) {
65 printf("Could not initialize Window\n");
66 }
67 if (SDL_CreateRenderer(windowID, -1, 0) != 0) {
68 printf("Could not create renderer\n");
69 }
70
71 /* Fill screen with black */
72 SDL_RenderFill(0, 0, 0, 0, NULL);
73
74 /* Enter render loop, waiting for user to quit */
75 done = 0;
76 while (!done) {
77 while (SDL_PollEvent(&event)) {
78 if (event.type == SDL_QUIT) {
79 done = 1;
80 }
81 }
82 render();
83 SDL_Delay(1);
84 }
85
86 /* shutdown SDL */
87 SDL_Quit();
88
89 return 0;
90 }