Mercurial > sdl-ios-xcode
comparison Xcode-iPhoneOS/Demos/src/rectangles.c @ 5211:78db79f5a4e2
Updated the iPhone demos for the new API
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 06 Feb 2011 09:02:10 -0800 |
parents | 64ce267332c6 |
children |
comparison
equal
deleted
inserted
replaced
5210:443a850284a1 | 5211:78db79f5a4e2 |
---|---|
7 #include "SDL.h" | 7 #include "SDL.h" |
8 #include <time.h> | 8 #include <time.h> |
9 #include "common.h" | 9 #include "common.h" |
10 | 10 |
11 void | 11 void |
12 render(void) | 12 render(SDL_Renderer *renderer) |
13 { | 13 { |
14 | 14 |
15 Uint8 r, g, b; | 15 Uint8 r, g, b; |
16 /* Come up with a random rectangle */ | 16 /* Come up with a random rectangle */ |
17 SDL_Rect rect; | 17 SDL_Rect rect; |
24 r = randomInt(50, 255); | 24 r = randomInt(50, 255); |
25 g = randomInt(50, 255); | 25 g = randomInt(50, 255); |
26 b = randomInt(50, 255); | 26 b = randomInt(50, 255); |
27 | 27 |
28 /* Fill the rectangle in the color */ | 28 /* Fill the rectangle in the color */ |
29 SDL_SetRenderDrawColor(r, g, b, 255); | 29 SDL_SetRenderDrawColor(renderer, r, g, b, 255); |
30 SDL_RenderFill(&rect); | 30 SDL_RenderFillRect(renderer, &rect); |
31 | 31 |
32 /* update screen */ | 32 /* update screen */ |
33 SDL_RenderPresent(); | 33 SDL_RenderPresent(renderer); |
34 | 34 |
35 } | 35 } |
36 | 36 |
37 int | 37 int |
38 main(int argc, char *argv[]) | 38 main(int argc, char *argv[]) |
39 { | 39 { |
40 | 40 |
41 SDL_Window *window; | 41 SDL_Window *window; |
42 SDL_Renderer *renderer; | |
42 int done; | 43 int done; |
43 SDL_Event event; | 44 SDL_Event event; |
44 | 45 |
45 /* initialize SDL */ | 46 /* initialize SDL */ |
46 if (SDL_Init(SDL_INIT_VIDEO) < 0) { | 47 if (SDL_Init(SDL_INIT_VIDEO) < 0) { |
55 SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, | 56 SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, |
56 SDL_WINDOW_SHOWN); | 57 SDL_WINDOW_SHOWN); |
57 if (window == 0) { | 58 if (window == 0) { |
58 fatalError("Could not initialize Window"); | 59 fatalError("Could not initialize Window"); |
59 } | 60 } |
60 if (SDL_CreateRenderer(window, -1, 0) != 0) { | 61 renderer = SDL_CreateRenderer(window, -1, 0); |
62 if (!renderer) { | |
61 fatalError("Could not create renderer"); | 63 fatalError("Could not create renderer"); |
62 } | 64 } |
63 | 65 |
64 /* Fill screen with black */ | 66 /* Fill screen with black */ |
65 SDL_SetRenderDrawColor(0, 0, 0, 255); | 67 SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); |
66 SDL_RenderFill(NULL); | 68 SDL_RenderClear(renderer); |
67 | 69 |
68 /* Enter render loop, waiting for user to quit */ | 70 /* Enter render loop, waiting for user to quit */ |
69 done = 0; | 71 done = 0; |
70 while (!done) { | 72 while (!done) { |
71 while (SDL_PollEvent(&event)) { | 73 while (SDL_PollEvent(&event)) { |
72 if (event.type == SDL_QUIT) { | 74 if (event.type == SDL_QUIT) { |
73 done = 1; | 75 done = 1; |
74 } | 76 } |
75 } | 77 } |
76 render(); | 78 render(renderer); |
77 SDL_Delay(1); | 79 SDL_Delay(1); |
78 } | 80 } |
79 | 81 |
80 /* shutdown SDL */ | 82 /* shutdown SDL */ |
81 SDL_Quit(); | 83 SDL_Quit(); |