Mercurial > sdl-ios-xcode
comparison test/testsprite2.c @ 5141:da10636e5eca
Making the API simpler, scaling is always defined as linear interpolation and should be supported as much as possible on all renderers.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 31 Jan 2011 22:44:43 -0800 |
parents | aa8888658021 |
children | e743b9c3f6d6 |
comparison
equal
deleted
inserted
replaced
5140:e594f07297a9 | 5141:da10636e5eca |
---|---|
19 static int current_color = 0; | 19 static int current_color = 0; |
20 static SDL_Rect *positions; | 20 static SDL_Rect *positions; |
21 static SDL_Rect *velocities; | 21 static SDL_Rect *velocities; |
22 static int sprite_w, sprite_h; | 22 static int sprite_w, sprite_h; |
23 static SDL_BlendMode blendMode = SDL_BLENDMODE_MASK; | 23 static SDL_BlendMode blendMode = SDL_BLENDMODE_MASK; |
24 static SDL_ScaleMode scaleMode = SDL_SCALEMODE_NONE; | |
25 | 24 |
26 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ | 25 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ |
27 static void | 26 static void |
28 quit(int rc) | 27 quit(int rc) |
29 { | 28 { |
87 fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError()); | 86 fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError()); |
88 SDL_FreeSurface(temp); | 87 SDL_FreeSurface(temp); |
89 return (-1); | 88 return (-1); |
90 } | 89 } |
91 SDL_SetTextureBlendMode(sprites[i], blendMode); | 90 SDL_SetTextureBlendMode(sprites[i], blendMode); |
92 SDL_SetTextureScaleMode(sprites[i], scaleMode); | |
93 } | 91 } |
94 SDL_FreeSurface(temp); | 92 SDL_FreeSurface(temp); |
95 | 93 |
96 /* We're ready to roll. :) */ | 94 /* We're ready to roll. :) */ |
97 return (0); | 95 return (0); |
251 } else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) { | 249 } else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) { |
252 blendMode = SDL_BLENDMODE_MOD; | 250 blendMode = SDL_BLENDMODE_MOD; |
253 consumed = 2; | 251 consumed = 2; |
254 } | 252 } |
255 } | 253 } |
256 } else if (SDL_strcasecmp(argv[i], "--scale") == 0) { | |
257 if (argv[i + 1]) { | |
258 if (SDL_strcasecmp(argv[i + 1], "none") == 0) { | |
259 scaleMode = SDL_SCALEMODE_NONE; | |
260 consumed = 2; | |
261 } else if (SDL_strcasecmp(argv[i + 1], "fast") == 0) { | |
262 scaleMode = SDL_SCALEMODE_FAST; | |
263 consumed = 2; | |
264 } else if (SDL_strcasecmp(argv[i + 1], "slow") == 0) { | |
265 scaleMode = SDL_SCALEMODE_SLOW; | |
266 consumed = 2; | |
267 } else if (SDL_strcasecmp(argv[i + 1], "best") == 0) { | |
268 scaleMode = SDL_SCALEMODE_BEST; | |
269 consumed = 2; | |
270 } | |
271 } | |
272 } else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) { | 254 } else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) { |
273 cycle_color = SDL_TRUE; | 255 cycle_color = SDL_TRUE; |
274 consumed = 1; | 256 consumed = 1; |
275 } else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) { | 257 } else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) { |
276 cycle_alpha = SDL_TRUE; | 258 cycle_alpha = SDL_TRUE; |
280 consumed = 1; | 262 consumed = 1; |
281 } | 263 } |
282 } | 264 } |
283 if (consumed < 0) { | 265 if (consumed < 0) { |
284 fprintf(stderr, | 266 fprintf(stderr, |
285 "Usage: %s %s [--blend none|mask|blend|add|mod] [--scale none|fast|slow|best] [--cyclecolor] [--cyclealpha]\n", | 267 "Usage: %s %s [--blend none|mask|blend|add|mod] [--cyclecolor] [--cyclealpha]\n", |
286 argv[0], CommonUsage(state)); | 268 argv[0], CommonUsage(state)); |
287 quit(1); | 269 quit(1); |
288 } | 270 } |
289 i += consumed; | 271 i += consumed; |
290 } | 272 } |
314 if (!positions || !velocities) { | 296 if (!positions || !velocities) { |
315 fprintf(stderr, "Out of memory!\n"); | 297 fprintf(stderr, "Out of memory!\n"); |
316 quit(2); | 298 quit(2); |
317 } | 299 } |
318 srand((unsigned int)time(NULL)); | 300 srand((unsigned int)time(NULL)); |
319 if (scaleMode != SDL_SCALEMODE_NONE) { | |
320 sprite_w += sprite_w / 2; | |
321 sprite_h += sprite_h / 2; | |
322 } | |
323 for (i = 0; i < num_sprites; ++i) { | 301 for (i = 0; i < num_sprites; ++i) { |
324 positions[i].x = rand() % (state->window_w - sprite_w); | 302 positions[i].x = rand() % (state->window_w - sprite_w); |
325 positions[i].y = rand() % (state->window_h - sprite_h); | 303 positions[i].y = rand() % (state->window_h - sprite_h); |
326 positions[i].w = sprite_w; | 304 positions[i].w = sprite_w; |
327 positions[i].h = sprite_h; | 305 positions[i].h = sprite_h; |