Mercurial > sdl-ios-xcode
comparison test/testsprite2.c @ 2884:9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
From: Couriersud
Subject: Re: Aw: Experience using SDL1.3 in sdlmame/Proposal for api additions
> For consistency you'd probably want:
> SDL_SetRenderDrawColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a);
> SDL_SetRenderDrawBlendMode(SDL_BlendMode blendMode);
> SDL_RenderLine(int x1, int y1, int x2, int y2);
> SDL_RenderFill(SDL_Rect *rect);
>
> You probably also want to add API functions query the current state.
>
I have implemented the above api for the opengl, x11, directfb and
software renderers. I have also renamed *TEXTUREBLENDMODE* constants to
BLENDMODE*. The unix build compiles. The windows renderer still needs to
be updated, but I have no windows development machine at hand. Have a
look at the x11 renderer for a sample.
Vector games now run at 90% both on opengl and directfb in comparison to
sdlmame's own opengl renderer. The same applies to raster games.
The diff also includes
a) Changed XDrawRect to XFillRect in x11 renderer
b) A number of changes to fix blending and modulation issues in the
directfb renderer.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 20 Dec 2008 12:00:00 +0000 |
parents | feb6ccdb888f |
children | d1436442215f |
comparison
equal
deleted
inserted
replaced
2883:11626a53e7bc | 2884:9dde605c7540 |
---|---|
18 static int current_alpha = 0; | 18 static int current_alpha = 0; |
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_TextureBlendMode blendMode = SDL_TEXTUREBLENDMODE_MASK; | 23 static SDL_BlendMode blendMode = SDL_BLENDMODE_MASK; |
24 static SDL_TextureScaleMode scaleMode = SDL_TEXTURESCALEMODE_NONE; | 24 static SDL_TextureScaleMode scaleMode = SDL_TEXTURESCALEMODE_NONE; |
25 | 25 |
26 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ | 26 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ |
27 static void | 27 static void |
28 quit(int rc) | 28 quit(int rc) |
117 SDL_SetTextureAlphaMod(sprite, (Uint8) current_alpha); | 117 SDL_SetTextureAlphaMod(sprite, (Uint8) current_alpha); |
118 } | 118 } |
119 | 119 |
120 /* Move the sprite, bounce at the wall, and draw */ | 120 /* Move the sprite, bounce at the wall, and draw */ |
121 n = 0; | 121 n = 0; |
122 SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL); | 122 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); |
123 SDL_RenderFill(NULL); | |
123 for (i = 0; i < num_sprites; ++i) { | 124 for (i = 0; i < num_sprites; ++i) { |
124 position = &positions[i]; | 125 position = &positions[i]; |
125 velocity = &velocities[i]; | 126 velocity = &velocities[i]; |
126 position->x += velocity->x; | 127 position->x += velocity->x; |
127 if ((position->x < 0) || (position->x >= (window_w - sprite_w))) { | 128 if ((position->x < 0) || (position->x >= (window_w - sprite_w))) { |
164 if (consumed == 0) { | 165 if (consumed == 0) { |
165 consumed = -1; | 166 consumed = -1; |
166 if (SDL_strcasecmp(argv[i], "--blend") == 0) { | 167 if (SDL_strcasecmp(argv[i], "--blend") == 0) { |
167 if (argv[i + 1]) { | 168 if (argv[i + 1]) { |
168 if (SDL_strcasecmp(argv[i + 1], "none") == 0) { | 169 if (SDL_strcasecmp(argv[i + 1], "none") == 0) { |
169 blendMode = SDL_TEXTUREBLENDMODE_NONE; | 170 blendMode = SDL_BLENDMODE_NONE; |
170 consumed = 2; | 171 consumed = 2; |
171 } else if (SDL_strcasecmp(argv[i + 1], "mask") == 0) { | 172 } else if (SDL_strcasecmp(argv[i + 1], "mask") == 0) { |
172 blendMode = SDL_TEXTUREBLENDMODE_MASK; | 173 blendMode = SDL_BLENDMODE_MASK; |
173 consumed = 2; | 174 consumed = 2; |
174 } else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) { | 175 } else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) { |
175 blendMode = SDL_TEXTUREBLENDMODE_BLEND; | 176 blendMode = SDL_BLENDMODE_BLEND; |
176 consumed = 2; | 177 consumed = 2; |
177 } else if (SDL_strcasecmp(argv[i + 1], "add") == 0) { | 178 } else if (SDL_strcasecmp(argv[i + 1], "add") == 0) { |
178 blendMode = SDL_TEXTUREBLENDMODE_ADD; | 179 blendMode = SDL_BLENDMODE_ADD; |
179 consumed = 2; | 180 consumed = 2; |
180 } else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) { | 181 } else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) { |
181 blendMode = SDL_TEXTUREBLENDMODE_MOD; | 182 blendMode = SDL_BLENDMODE_MOD; |
182 consumed = 2; | 183 consumed = 2; |
183 } | 184 } |
184 } | 185 } |
185 } else if (SDL_strcasecmp(argv[i], "--scale") == 0) { | 186 } else if (SDL_strcasecmp(argv[i], "--scale") == 0) { |
186 if (argv[i + 1]) { | 187 if (argv[i + 1]) { |
228 fprintf(stderr, "Out of memory!\n"); | 229 fprintf(stderr, "Out of memory!\n"); |
229 quit(2); | 230 quit(2); |
230 } | 231 } |
231 for (i = 0; i < state->num_windows; ++i) { | 232 for (i = 0; i < state->num_windows; ++i) { |
232 SDL_SelectRenderer(state->windows[i]); | 233 SDL_SelectRenderer(state->windows[i]); |
233 SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL); | 234 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); |
235 SDL_RenderFill(NULL); | |
234 } | 236 } |
235 if (LoadSprite("icon.bmp") < 0) { | 237 if (LoadSprite("icon.bmp") < 0) { |
236 quit(2); | 238 quit(2); |
237 } | 239 } |
238 | 240 |
273 switch (event.type) { | 275 switch (event.type) { |
274 case SDL_WINDOWEVENT: | 276 case SDL_WINDOWEVENT: |
275 switch (event.window.event) { | 277 switch (event.window.event) { |
276 case SDL_WINDOWEVENT_EXPOSED: | 278 case SDL_WINDOWEVENT_EXPOSED: |
277 SDL_SelectRenderer(event.window.windowID); | 279 SDL_SelectRenderer(event.window.windowID); |
278 SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL); | 280 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); |
281 SDL_RenderFill(NULL); | |
279 break; | 282 break; |
280 } | 283 } |
281 break; | 284 break; |
282 default: | 285 default: |
283 break; | 286 break; |