Skip to content

Commit 96adbfe

Browse files
committed
fix(gfx): SPRITE STAMP cells honour SPRITEMODULATE
Cell-list render in gfx_sprite_composite_range was passing WHITE as the DrawTexturePro tint, so STAMP-based renders ignored the slot's mod_a / mod_r / mod_g / mod_b. SPRITE DRAW already read the mods correctly; STAMP did not. The shadow pattern (load duplicate slot, SPRITEMODULATE alpha+black, stamp at an offset) only worked for the player (drawn via DRAW) — multi-instance enemy ship shadows came out fully opaque. Read the slot's mod under the sprite mutex once per cell and pass as the tint; cost is one extra mutex per cell, negligible at the cell counts we run.
1 parent 38d47af commit 96adbfe

1 file changed

Lines changed: 32 additions & 17 deletions

File tree

gfx/gfx_raylib.c

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,23 +1415,38 @@ static void gfx_sprite_composite_range(const GfxVideoState *vs, RenderTexture2D
14151415
pthread_mutex_unlock(&g_sprite_mutex);
14161416
src = (Rectangle){ (float)cell->sx, (float)cell->sy,
14171417
(float)cell->sw, (float)cell->sh };
1418-
/* When rotating, DrawTexturePro rotates around the origin
1419-
* argument — offset by half the destination size so rotation
1420-
* pivots around the sprite's centre, then add back to keep
1421-
* the cell's (x, y) meaning "top-left of the un-rotated
1422-
* quad". */
1423-
if (cell->rot != 0.0f) {
1424-
dest = (Rectangle){ cell->x - scx + (float)cell->sw * 0.5f,
1425-
cell->y - scy + (float)cell->sh * 0.5f,
1426-
(float)cell->sw, (float)cell->sh };
1427-
DrawTexturePro(t, src, dest,
1428-
(Vector2){ (float)cell->sw * 0.5f,
1429-
(float)cell->sh * 0.5f },
1430-
cell->rot, WHITE);
1431-
} else {
1432-
dest = (Rectangle){ cell->x - scx, cell->y - scy,
1433-
(float)cell->sw, (float)cell->sh };
1434-
DrawTexturePro(t, src, dest, (Vector2){ 0, 0 }, 0.0f, WHITE);
1418+
/* Honour SPRITEMODULATE on the source slot. Without this,
1419+
* STAMP cells render at full opacity and ignore tint —
1420+
* SPRITEMODULATE only affected SPRITE DRAW. The shadow
1421+
* pattern (a duplicate sprite slot with alpha+black mod
1422+
* stamped at an offset) needs the cell list to apply the
1423+
* slot's mod_a/r/g/b too. */
1424+
{
1425+
Color tint;
1426+
pthread_mutex_lock(&g_sprite_mutex);
1427+
tint.r = (unsigned char)g_sprite_slots[s].mod_r;
1428+
tint.g = (unsigned char)g_sprite_slots[s].mod_g;
1429+
tint.b = (unsigned char)g_sprite_slots[s].mod_b;
1430+
tint.a = (unsigned char)g_sprite_slots[s].mod_a;
1431+
pthread_mutex_unlock(&g_sprite_mutex);
1432+
/* When rotating, DrawTexturePro rotates around the
1433+
* origin argument — offset by half the destination
1434+
* size so rotation pivots around the sprite's centre,
1435+
* then add back to keep the cell's (x, y) meaning
1436+
* "top-left of the un-rotated quad". */
1437+
if (cell->rot != 0.0f) {
1438+
dest = (Rectangle){ cell->x - scx + (float)cell->sw * 0.5f,
1439+
cell->y - scy + (float)cell->sh * 0.5f,
1440+
(float)cell->sw, (float)cell->sh };
1441+
DrawTexturePro(t, src, dest,
1442+
(Vector2){ (float)cell->sw * 0.5f,
1443+
(float)cell->sh * 0.5f },
1444+
cell->rot, tint);
1445+
} else {
1446+
dest = (Rectangle){ cell->x - scx, cell->y - scy,
1447+
(float)cell->sw, (float)cell->sh };
1448+
DrawTexturePro(t, src, dest, (Vector2){ 0, 0 }, 0.0f, tint);
1449+
}
14351450
}
14361451
}
14371452
}

0 commit comments

Comments
 (0)