Mercurial > sdl-ios-xcode
comparison Xcode-iPhoneOS/Demos/src/mixer.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 | 06c7423f8c60 |
children |
comparison
equal
deleted
inserted
replaced
5210:443a850284a1 | 5211:78db79f5a4e2 |
---|---|
31 | 31 |
32 /* function declarations */ | 32 /* function declarations */ |
33 void handleMouseButtonDown(SDL_Event * event); | 33 void handleMouseButtonDown(SDL_Event * event); |
34 void handleMouseButtonUp(SDL_Event * event); | 34 void handleMouseButtonUp(SDL_Event * event); |
35 int playSound(struct sound *); | 35 int playSound(struct sound *); |
36 void render(void); | |
37 void initializeButtons(); | 36 void initializeButtons(); |
38 void audioCallback(void *userdata, Uint8 * stream, int len); | 37 void audioCallback(void *userdata, Uint8 * stream, int len); |
39 void loadSound(const char *file, struct sound *s); | 38 void loadSound(const char *file, struct sound *s); |
40 | 39 |
41 struct | 40 struct |
161 } | 160 } |
162 } | 161 } |
163 | 162 |
164 /* draws buttons to screen */ | 163 /* draws buttons to screen */ |
165 void | 164 void |
166 render(void) | 165 render(SDL_Renderer *renderer) |
167 { | 166 { |
168 int i; | 167 int i; |
169 SDL_SetRenderDrawColor(50, 50, 50, 255); | 168 SDL_SetRenderDrawColor(renderer, 50, 50, 50, 255); |
170 SDL_RenderFill(NULL); /* draw background (gray) */ | 169 SDL_RenderClear(renderer); /* draw background (gray) */ |
171 /* draw the drum buttons */ | 170 /* draw the drum buttons */ |
172 for (i = 0; i < NUM_DRUMS; i++) { | 171 for (i = 0; i < NUM_DRUMS; i++) { |
173 SDL_Color color = | 172 SDL_Color color = |
174 buttons[i].isPressed ? buttons[i].downColor : buttons[i].upColor; | 173 buttons[i].isPressed ? buttons[i].downColor : buttons[i].upColor; |
175 SDL_SetRenderDrawColor(color.r, color.g, color.b, color.unused); | 174 SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.unused); |
176 SDL_RenderFill(&buttons[i].rect); | 175 SDL_RenderFillRect(renderer, &buttons[i].rect); |
177 } | 176 } |
178 /* update the screen */ | 177 /* update the screen */ |
179 SDL_RenderPresent(); | 178 SDL_RenderPresent(renderer); |
180 } | 179 } |
181 | 180 |
182 /* | 181 /* |
183 finds a sound channel in the mixer for a sound | 182 finds a sound channel in the mixer for a sound |
184 and sets it up to start playing | 183 and sets it up to start playing |
272 main(int argc, char *argv[]) | 271 main(int argc, char *argv[]) |
273 { | 272 { |
274 | 273 |
275 int done; /* has user tried to quit ? */ | 274 int done; /* has user tried to quit ? */ |
276 SDL_Window *window; /* main window */ | 275 SDL_Window *window; /* main window */ |
276 SDL_Renderer *renderer; | |
277 SDL_Event event; | 277 SDL_Event event; |
278 Uint32 startFrame; /* holds when frame started processing */ | 278 Uint32 startFrame; /* holds when frame started processing */ |
279 Uint32 endFrame; /* holds when frame ended processing */ | 279 Uint32 endFrame; /* holds when frame ended processing */ |
280 Uint32 delay; /* calculated delay, how long should we wait before next frame? */ | 280 Uint32 delay; /* calculated delay, how long should we wait before next frame? */ |
281 | 281 |
283 fatalError("could not initialize SDL"); | 283 fatalError("could not initialize SDL"); |
284 } | 284 } |
285 window = | 285 window = |
286 SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, | 286 SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, |
287 SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS); | 287 SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS); |
288 SDL_CreateRenderer(window, 0, 0); | 288 renderer = SDL_CreateRenderer(window, 0, 0); |
289 | 289 |
290 /* initialize the mixer */ | 290 /* initialize the mixer */ |
291 SDL_memset(&mixer, 0, sizeof(mixer)); | 291 SDL_memset(&mixer, 0, sizeof(mixer)); |
292 /* setup output format */ | 292 /* setup output format */ |
293 mixer.outputSpec.freq = 44100; | 293 mixer.outputSpec.freq = 44100; |
326 case SDL_QUIT: | 326 case SDL_QUIT: |
327 done = 1; | 327 done = 1; |
328 break; | 328 break; |
329 } | 329 } |
330 } | 330 } |
331 render(); /* draw buttons */ | 331 render(renderer); /* draw buttons */ |
332 endFrame = SDL_GetTicks(); | 332 endFrame = SDL_GetTicks(); |
333 | 333 |
334 /* figure out how much time we have left, and then sleep */ | 334 /* figure out how much time we have left, and then sleep */ |
335 delay = MILLESECONDS_PER_FRAME - (endFrame - startFrame); | 335 delay = MILLESECONDS_PER_FRAME - (endFrame - startFrame); |
336 if (delay < 0) { | 336 if (delay < 0) { |