annotate Xcode-iPhoneOS/Demos/src/rectangles.c @ 5225:1fbe1c202501

Renamed SDL_Key to SDL_Keycode to clarify terminology.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 07 Feb 2011 10:40:21 -0800
parents 78db79f5a4e2
children
rev   line source
3277
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 * rectangles.c
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 * written by Holmes Futrell
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4 * use however you want
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 */
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 #include "SDL.h"
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 #include <time.h>
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9 #include "common.h"
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 void
5211
78db79f5a4e2 Updated the iPhone demos for the new API
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
12 render(SDL_Renderer *renderer)
3277
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 {
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 Uint8 r, g, b;
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 /* Come up with a random rectangle */
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 SDL_Rect rect;
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18 rect.w = randomInt(64, 128);
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 rect.h = randomInt(64, 128);
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 rect.x = randomInt(0, SCREEN_WIDTH);
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 rect.y = randomInt(0, SCREEN_HEIGHT);
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 /* Come up with a random color */
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 r = randomInt(50, 255);
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 g = randomInt(50, 255);
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 b = randomInt(50, 255);
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 /* Fill the rectangle in the color */
5211
78db79f5a4e2 Updated the iPhone demos for the new API
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
29 SDL_SetRenderDrawColor(renderer, r, g, b, 255);
78db79f5a4e2 Updated the iPhone demos for the new API
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
30 SDL_RenderFillRect(renderer, &rect);
3277
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 /* update screen */
5211
78db79f5a4e2 Updated the iPhone demos for the new API
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
33 SDL_RenderPresent(renderer);
3277
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 }
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 int
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 main(int argc, char *argv[])
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 {
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3277
diff changeset
41 SDL_Window *window;
5211
78db79f5a4e2 Updated the iPhone demos for the new API
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
42 SDL_Renderer *renderer;
3277
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 int done;
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 SDL_Event event;
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 /* initialize SDL */
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 fatalError("Could not initialize SDL");
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 }
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 /* seed random number generator */
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 srand(time(NULL));
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 /* create window and renderer */
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3277
diff changeset
55 window =
3277
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 SDL_WINDOW_SHOWN);
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3277
diff changeset
58 if (window == 0) {
3277
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 fatalError("Could not initialize Window");
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 }
5211
78db79f5a4e2 Updated the iPhone demos for the new API
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
61 renderer = SDL_CreateRenderer(window, -1, 0);
78db79f5a4e2 Updated the iPhone demos for the new API
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
62 if (!renderer) {
3277
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 fatalError("Could not create renderer");
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 }
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 /* Fill screen with black */
5211
78db79f5a4e2 Updated the iPhone demos for the new API
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
67 SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
78db79f5a4e2 Updated the iPhone demos for the new API
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
68 SDL_RenderClear(renderer);
3277
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 /* Enter render loop, waiting for user to quit */
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 done = 0;
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 while (!done) {
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 while (SDL_PollEvent(&event)) {
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 if (event.type == SDL_QUIT) {
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 done = 1;
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 }
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 }
5211
78db79f5a4e2 Updated the iPhone demos for the new API
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
78 render(renderer);
3277
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 SDL_Delay(1);
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 }
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 /* shutdown SDL */
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 SDL_Quit();
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 return 0;
20326ba2bda2 This name inconsistency has been bugging me for a while...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 }