comparison test/testsprite2.c @ 1916:c773b0c0ac89

Implemented blend modes in the D3D renderer
author Sam Lantinga <slouken@libsdl.org>
date Wed, 19 Jul 2006 05:03:21 +0000
parents a228436a2404
children 3f54b3ec5a07
comparison
equal deleted inserted replaced
1915:a228436a2404 1916:c773b0c0ac89
6 6
7 #include "common.h" 7 #include "common.h"
8 8
9 #define NUM_SPRITES 100 9 #define NUM_SPRITES 100
10 #define MAX_SPEED 1 10 #define MAX_SPEED 1
11 #define BACKGROUND 0x00FFFFFF 11 #define BACKGROUND 0x00A0A0A0
12 12
13 static CommonState *state; 13 static CommonState *state;
14 static int num_sprites; 14 static int num_sprites;
15 static SDL_TextureID *sprites; 15 static SDL_TextureID *sprites;
16 static SDL_Rect *positions; 16 static SDL_Rect *positions;
17 static SDL_Rect *velocities; 17 static SDL_Rect *velocities;
18 static int sprite_w, sprite_h; 18 static int sprite_w, sprite_h;
19 static SDL_TextureBlendMode blendMode = SDL_TextureBlendMode_Mask;
19 20
20 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ 21 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
21 static void 22 static void
22 quit(int rc) 23 quit(int rc)
23 { 24 {
105 velocity->y = -velocity->y; 106 velocity->y = -velocity->y;
106 position->y += velocity->y; 107 position->y += velocity->y;
107 } 108 }
108 109
109 /* Blit the sprite onto the screen */ 110 /* Blit the sprite onto the screen */
110 SDL_RenderCopy(sprite, NULL, position, SDL_TextureBlendMode_Mask, 111 SDL_RenderCopy(sprite, NULL, position, blendMode,
111 SDL_TextureScaleMode_None); 112 SDL_TextureScaleMode_None);
112 } 113 }
113 114
114 /* Update the screen! */ 115 /* Update the screen! */
115 SDL_RenderPresent(); 116 SDL_RenderPresent();
133 for (i = 1; i < argc;) { 134 for (i = 1; i < argc;) {
134 int consumed; 135 int consumed;
135 136
136 consumed = CommonArg(state, i); 137 consumed = CommonArg(state, i);
137 if (consumed == 0) { 138 if (consumed == 0) {
138 num_sprites = SDL_atoi(argv[i]); 139 consumed = -1;
139 consumed = 1; 140 if (SDL_strcasecmp(argv[i], "--blend") == 0) {
141 if (argv[i + 1]) {
142 if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
143 blendMode = SDL_TextureBlendMode_None;
144 consumed = 2;
145 } else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) {
146 blendMode = SDL_TextureBlendMode_Blend;
147 consumed = 2;
148 } else if (SDL_strcasecmp(argv[i + 1], "add") == 0) {
149 blendMode = SDL_TextureBlendMode_Add;
150 consumed = 2;
151 } else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) {
152 blendMode = SDL_TextureBlendMode_Mod;
153 consumed = 2;
154 }
155 }
156 } else if (SDL_isdigit(*argv[i])) {
157 num_sprites = SDL_atoi(argv[i]);
158 consumed = 1;
159 }
140 } 160 }
141 if (consumed < 0) { 161 if (consumed < 0) {
142 fprintf(stderr, "Usage: %s %s", argv[0], CommonUsage(state)); 162 fprintf(stderr, "Usage: %s %s [--blend none|blend|add|mod]",
163 argv[0], CommonUsage(state));
143 quit(1); 164 quit(1);
144 } 165 }
145 i += consumed; 166 i += consumed;
146 } 167 }
147 if (!CommonInit(state)) { 168 if (!CommonInit(state)) {