Commit 9eea51e2 authored by Sam Lantinga's avatar Sam Lantinga

Implemented blend modes in the D3D renderer

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401961
parent f2c82961
...@@ -750,6 +750,8 @@ SDL_strcasecmp(const char *str1, const char *str2) ...@@ -750,6 +750,8 @@ SDL_strcasecmp(const char *str1, const char *str2)
++str1; ++str1;
++str2; ++str2;
} }
a = SDL_tolower(*str1);
b = SDL_tolower(*str2);
return (int) ((unsigned char) a - (unsigned char) b); return (int) ((unsigned char) a - (unsigned char) b);
} }
#endif #endif
...@@ -769,6 +771,8 @@ SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen) ...@@ -769,6 +771,8 @@ SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen)
++str2; ++str2;
--maxlen; --maxlen;
} }
a = SDL_tolower(*str1);
b = SDL_tolower(*str2);
return (int) ((unsigned char) a - (unsigned char) b); return (int) ((unsigned char) a - (unsigned char) b);
} }
#endif #endif
......
...@@ -359,12 +359,6 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags) ...@@ -359,12 +359,6 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE, IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
D3DCULL_NONE); D3DCULL_NONE);
IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE); IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE);
IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
TRUE);
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
D3DBLEND_SRCALPHA);
IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
D3DBLEND_INVSRCALPHA);
return renderer; return renderer;
} }
...@@ -627,6 +621,38 @@ D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, ...@@ -627,6 +621,38 @@ D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
vertices[3].u = minu; vertices[3].u = minu;
vertices[3].v = maxv; vertices[3].v = maxv;
switch (blendMode) {
case SDL_TextureBlendMode_None:
IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
FALSE);
break;
case SDL_TextureBlendMode_Mask:
case SDL_TextureBlendMode_Blend:
IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
TRUE);
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
D3DBLEND_SRCALPHA);
IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
D3DBLEND_INVSRCALPHA);
break;
case SDL_TextureBlendMode_Add:
IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
TRUE);
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
D3DBLEND_SRCALPHA);
IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
D3DBLEND_ONE);
break;
case SDL_TextureBlendMode_Mod:
IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
TRUE);
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
D3DBLEND_ZERO);
IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
D3DBLEND_SRCCOLOR);
break;
}
result = result =
IDirect3DDevice9_SetTexture(data->device, 0, IDirect3DDevice9_SetTexture(data->device, 0,
(IDirect3DBaseTexture9 *) texturedata-> (IDirect3DBaseTexture9 *) texturedata->
......
...@@ -105,7 +105,7 @@ CommonArg(CommonState * state, int index) ...@@ -105,7 +105,7 @@ CommonArg(CommonState * state, int index)
} }
if (SDL_strcasecmp(argv[index], "--windows") == 0) { if (SDL_strcasecmp(argv[index], "--windows") == 0) {
++index; ++index;
if (!argv[index] || !isdigit(*argv[index])) { if (!argv[index] || !SDL_isdigit(*argv[index])) {
return -1; return -1;
} }
if (!(state->window_flags & SDL_WINDOW_FULLSCREEN)) { if (!(state->window_flags & SDL_WINDOW_FULLSCREEN)) {
......
...@@ -193,7 +193,7 @@ main(int argc, char *argv[]) ...@@ -193,7 +193,7 @@ main(int argc, char *argv[])
} }
} }
if (consumed < 0) { if (consumed < 0) {
fprintf(stderr, "Usage: %s [--fsaa] [--accel] %s", argv[0], fprintf(stderr, "Usage: %s %s [--fsaa] [--accel]", argv[0],
CommonUsage(state)); CommonUsage(state));
quit(1); quit(1);
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#define NUM_SPRITES 100 #define NUM_SPRITES 100
#define MAX_SPEED 1 #define MAX_SPEED 1
#define BACKGROUND 0x00FFFFFF #define BACKGROUND 0x00A0A0A0
static CommonState *state; static CommonState *state;
static int num_sprites; static int num_sprites;
...@@ -16,6 +16,7 @@ static SDL_TextureID *sprites; ...@@ -16,6 +16,7 @@ static SDL_TextureID *sprites;
static SDL_Rect *positions; static SDL_Rect *positions;
static SDL_Rect *velocities; static SDL_Rect *velocities;
static int sprite_w, sprite_h; static int sprite_w, sprite_h;
static SDL_TextureBlendMode blendMode = SDL_TextureBlendMode_Mask;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void static void
...@@ -107,7 +108,7 @@ MoveSprites(SDL_WindowID window, SDL_TextureID sprite) ...@@ -107,7 +108,7 @@ MoveSprites(SDL_WindowID window, SDL_TextureID sprite)
} }
/* Blit the sprite onto the screen */ /* Blit the sprite onto the screen */
SDL_RenderCopy(sprite, NULL, position, SDL_TextureBlendMode_Mask, SDL_RenderCopy(sprite, NULL, position, blendMode,
SDL_TextureScaleMode_None); SDL_TextureScaleMode_None);
} }
...@@ -135,11 +136,31 @@ main(int argc, char *argv[]) ...@@ -135,11 +136,31 @@ main(int argc, char *argv[])
consumed = CommonArg(state, i); consumed = CommonArg(state, i);
if (consumed == 0) { if (consumed == 0) {
num_sprites = SDL_atoi(argv[i]); consumed = -1;
consumed = 1; if (SDL_strcasecmp(argv[i], "--blend") == 0) {
if (argv[i + 1]) {
if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
blendMode = SDL_TextureBlendMode_None;
consumed = 2;
} else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) {
blendMode = SDL_TextureBlendMode_Blend;
consumed = 2;
} else if (SDL_strcasecmp(argv[i + 1], "add") == 0) {
blendMode = SDL_TextureBlendMode_Add;
consumed = 2;
} else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) {
blendMode = SDL_TextureBlendMode_Mod;
consumed = 2;
}
}
} else if (SDL_isdigit(*argv[i])) {
num_sprites = SDL_atoi(argv[i]);
consumed = 1;
}
} }
if (consumed < 0) { if (consumed < 0) {
fprintf(stderr, "Usage: %s %s", argv[0], CommonUsage(state)); fprintf(stderr, "Usage: %s %s [--blend none|blend|add|mod]",
argv[0], CommonUsage(state));
quit(1); quit(1);
} }
i += consumed; i += consumed;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment