diff --git a/include/gfx/gfx.h b/include/gfx/gfx.h index 14569e3..17c6d85 100644 --- a/include/gfx/gfx.h +++ b/include/gfx/gfx.h @@ -27,10 +27,10 @@ struct cg; struct text_metrics; enum draw_method { - DRAW_METHOD_NORMAL = 0, - DRAW_METHOD_SCREEN = 1, - DRAW_METHOD_MULTIPLY = 2, - NR_DRAW_METHODS + DRAW_METHOD_NORMAL, + DRAW_METHOD_SCREEN, + DRAW_METHOD_MULTIPLY, + DRAW_METHOD_ADDITIVE, }; typedef struct texture { diff --git a/include/sprite.h b/include/sprite.h index b1d9fed..184d147 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -72,8 +72,8 @@ static inline void sprite_set_z2(struct sact_sprite *sp, int z, int z2) { scene_ int sprite_get_blend_rate(struct sact_sprite *sp); void sprite_set_blend_rate(struct sact_sprite *sp, int rate); static inline void sprite_set_show(struct sact_sprite *sp, bool show) { scene_set_sprite_show(&sp->sp, show); } -int sprite_set_draw_method(struct sact_sprite *sp, int method); -int sprite_get_draw_method(struct sact_sprite *sp); +int sprite_set_draw_method(struct sact_sprite *sp, enum draw_method method); +enum draw_method sprite_get_draw_method(struct sact_sprite *sp); static inline int sprite_exists_alpha(struct sact_sprite *sp) { return sp->sp.has_alpha; } static inline int sprite_get_pos_x(struct sact_sprite *sp) { return sp->rect.x; } static inline int sprite_get_pos_y(struct sact_sprite *sp) { return sp->rect.y; } diff --git a/src/hll/SACT2.c b/src/hll/SACT2.c index 55345f1..39135e0 100644 --- a/src/hll/SACT2.c +++ b/src/hll/SACT2.c @@ -337,15 +337,29 @@ int sact_SP_SetDrawMethod(int sp_no, int method) { struct sact_sprite *sp = sact_get_sprite(sp_no); if (!sp) return 0; - return sprite_set_draw_method(sp, method); - return 1; + switch (method) { + case 0: return sprite_set_draw_method(sp, DRAW_METHOD_NORMAL); + case 1: return sprite_set_draw_method(sp, DRAW_METHOD_SCREEN); + case 2: return sprite_set_draw_method(sp, DRAW_METHOD_MULTIPLY); + default: + WARNING("unknown draw method: %d", method); + return 0; + } } int sact_SP_GetDrawMethod(int sp_no) { struct sact_sprite *sp = sact_try_get_sprite(sp_no); if (!sp) return DRAW_METHOD_NORMAL; - return sprite_get_draw_method(sp); + int method = sprite_get_draw_method(sp); + switch (method) { + case DRAW_METHOD_NORMAL: return 0; + case DRAW_METHOD_SCREEN: return 1; + case DRAW_METHOD_MULTIPLY: return 2; + default: + WARNING("unknown draw method: %d", method); + return 0; + } } int sact_SP_IsUsing(int sp_no) diff --git a/src/hll/StoatSpriteEngine.c b/src/hll/StoatSpriteEngine.c index 6ac9b06..e129cc9 100644 --- a/src/hll/StoatSpriteEngine.c +++ b/src/hll/StoatSpriteEngine.c @@ -44,6 +44,33 @@ HLL_WARN_UNIMPLEMENTED( , void, StoatSpriteEngine, SetVolumeMixerSEGroupNum, int HLL_WARN_UNIMPLEMENTED( , void, StoatSpriteEngine, SetVolumeMixerBGMGroupNum, int n); HLL_WARN_UNIMPLEMENTED(0, int, StoatSpriteEngine, Sound_GetGroupNumFromDataNum, int n); +static int StoatSpriteEngine_SP_SetDrawMethod(int sp_no, int method) +{ + struct sact_sprite *sp = sact_get_sprite(sp_no); + if (!sp) return 0; + switch (method) { + case 0: return sprite_set_draw_method(sp, DRAW_METHOD_NORMAL); + case 1: return sprite_set_draw_method(sp, DRAW_METHOD_ADDITIVE); + default: + WARNING("unknown draw method: %d", method); + return 0; + } +} + +static int StoatSpriteEngine_SP_GetDrawMethod(int sp_no) +{ + struct sact_sprite *sp = sact_try_get_sprite(sp_no); + if (!sp) return DRAW_METHOD_NORMAL; + int method = sprite_get_draw_method(sp); + switch (method) { + case DRAW_METHOD_NORMAL: return 0; + case DRAW_METHOD_ADDITIVE: return 1; + default: + WARNING("unknown draw method: %d", method); + return 0; + } +} + struct text_metrics text_sprite_tm = { .color = { .r = 255, .g = 255, .b = 255, .a = 255 }, .outline_color = { .r = 0, .g = 0, .b = 0, .a = 255 }, @@ -793,7 +820,7 @@ HLL_LIBRARY(StoatSpriteEngine, HLL_EXPORT(SP_SetZ, sact_SP_SetZ), HLL_EXPORT(SP_SetBlendRate, sact_SP_SetBlendRate), HLL_EXPORT(SP_SetShow, sact_SP_SetShow), - HLL_EXPORT(SP_SetDrawMethod, sact_SP_SetDrawMethod), + HLL_EXPORT(SP_SetDrawMethod, StoatSpriteEngine_SP_SetDrawMethod), HLL_EXPORT(SP_IsUsing, sact_SP_IsUsing), HLL_EXPORT(SP_ExistAlpha, sact_SP_ExistsAlpha), HLL_EXPORT(SP_GetPosX, sact_SP_GetPosX), @@ -803,7 +830,7 @@ HLL_LIBRARY(StoatSpriteEngine, HLL_EXPORT(SP_GetZ, sact_SP_GetZ), HLL_EXPORT(SP_GetBlendRate, sact_SP_GetBlendRate), HLL_EXPORT(SP_GetShow, sact_SP_GetShow), - HLL_EXPORT(SP_GetDrawMethod, sact_SP_GetDrawMethod), + HLL_EXPORT(SP_GetDrawMethod, StoatSpriteEngine_SP_GetDrawMethod), HLL_EXPORT(SP_SetTextHome, sact_SP_SetTextHome), HLL_EXPORT(SP_SetTextLineSpace, sact_SP_SetTextLineSpace), HLL_EXPORT(SP_SetTextCharSpace, sact_SP_SetTextCharSpace), diff --git a/src/sprite.c b/src/sprite.c index deadec1..0bdbb87 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -179,18 +179,14 @@ void sprite_set_blend_rate(struct sact_sprite *sp, int rate) sprite_dirty(sp); } -int sprite_set_draw_method(struct sact_sprite *sp, int method) +int sprite_set_draw_method(struct sact_sprite *sp, enum draw_method method) { - if (method < 0 || method >= NR_DRAW_METHODS) { - WARNING("unknown draw method: %d", method); - return 0; - } sprite_get_texture(sp)->draw_method = method; sprite_dirty(sp); return 1; } -int sprite_get_draw_method(struct sact_sprite *sp) +enum draw_method sprite_get_draw_method(struct sact_sprite *sp) { return sprite_get_texture(sp)->draw_method; } diff --git a/src/video.c b/src/video.c index 65b136d..5b0115a 100644 --- a/src/video.c +++ b/src/video.c @@ -419,6 +419,9 @@ void gfx_render_texture(struct texture *t, Rectangle *r) case DRAW_METHOD_MULTIPLY: glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_ZERO, GL_ONE); break; + case DRAW_METHOD_ADDITIVE: + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ZERO, GL_ONE); + break; default: // FIXME: why doesn't this work? //if (t->alpha_mod != 255) {