Skip to content

Commit

Permalink
Draw masked actors as textures (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Feb 18, 2018
1 parent 6e950a9 commit 2c89b45
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 58 deletions.
51 changes: 0 additions & 51 deletions src/cdogs/blit.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,57 +125,6 @@ void BlitPicHighlight(
}
}

void BlitBackground(
GraphicsDevice *device,
const Pic *pic, struct vec2i pos, const HSV *tint, const bool isTransparent)
{
Uint32 *current = pic->Data;
pos = svec2i_add(pos, pic->offset);
for (int i = 0; i < pic->size.y; i++)
{
int yoff = i + pos.y;
if (yoff > device->clipping.bottom)
{
break;
}
if (yoff < device->clipping.top)
{
current += pic->size.x;
continue;
}
yoff *= device->cachedConfig.Res.x;
for (int j = 0; j < pic->size.x; j++)
{
int xoff = j + pos.x;
if (xoff < device->clipping.left)
{
current++;
continue;
}
if (xoff > device->clipping.right)
{
current += pic->size.x - j;
break;
}
if ((isTransparent && *current) || !isTransparent)
{
Uint32 *target = gGraphicsDevice.buf + yoff + xoff;
if (tint != NULL)
{
const color_t targetColor = PIXEL2COLOR(*target);
const color_t blendedColor = ColorTint(targetColor, *tint);
*target = COLOR2PIXEL(blendedColor);
}
else
{
*target = *current;
}
}
current++;
}
}
}

void Blit(GraphicsDevice *device, const Pic *pic, struct vec2i pos)
{
Uint32 *current = pic->Data;
Expand Down
3 changes: 0 additions & 3 deletions src/cdogs/blit.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ typedef enum
} CharColorType;
color_t *CharColorGetByType(CharColors *c, const CharColorType t);

void BlitBackground(
GraphicsDevice *device,
const Pic *pic, struct vec2i pos, const HSV *tint, const bool isTransparent);
void Blit(GraphicsDevice *device, const Pic *pic, struct vec2i pos);
void BlitMasked(
GraphicsDevice *device,
Expand Down
13 changes: 9 additions & 4 deletions src/cdogs/draw/draw_actor.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,17 @@ void DrawActorPics(const ActorPics *pics, const struct vec2i pos)
const struct vec2i drawPos = svec2i_add(pos, pics->OrderedOffsets[i]);
if (pics->IsTransparent)
{
BlitBackground(
&gGraphicsDevice, pic, drawPos, pics->Tint, true);
color_t mask = ColorTint(colorWhite, *pics->Tint);
mask.a = 64;
PicRender(
pic, gGraphicsDevice.gameWindow.renderer, drawPos,
mask);
}
else if (pics->Mask != NULL)
{
BlitMasked(&gGraphicsDevice, pic, drawPos, *pics->Mask, true);
PicRender(
pic, gGraphicsDevice.gameWindow.renderer, drawPos,
*pics->Mask);
}
else
{
Expand Down Expand Up @@ -486,5 +491,5 @@ static void DrawDyingBody(
const struct vec2i drawPos = svec2i_subtract(pos, svec2i(
body->size.x / 2, body->size.y / 2 + DYING_BODY_OFFSET));
const color_t mask = pics->Mask != NULL ? *pics->Mask : colorWhite;
BlitMasked(g, pics->Body, drawPos, mask, true);
PicRender(body, g->gameWindow.renderer, drawPos, mask);
}

0 comments on commit 2c89b45

Please sign in to comment.