Parametrize drop shadows.

This commit is contained in:
Themaister 2014-06-08 12:44:40 +02:00
parent d129ff3d13
commit 64cc0efefe
2 changed files with 22 additions and 10 deletions

View File

@ -347,7 +347,9 @@ struct font_params
float x;
float y;
float scale;
uint32_t color; // ABGR.
float drop_mod; // Drop shadow color multiplier.
int drop_x, drop_y; // Drop shadow offset. If both are 0, no drop shadow will be rendered.
uint32_t color; // ABGR. Use the macros.
bool full_screen;
};
#define FONT_COLOR_RGBA(r, g, b, a) (((r) << 0) | ((g) << 8) | ((b) << 16) | ((a) << 24))

View File

@ -186,8 +186,9 @@ static void render_message(gl_raster_t *font, const char *msg, GLfloat scale, co
static void gl_render_msg(void *data, const char *msg, const struct font_params *params)
{
GLfloat x, y, scale;
GLfloat x, y, scale, drop_mod;
GLfloat color[4], color_dark[4];
int drop_x, drop_y;
bool full_screen;
gl_raster_t *font = (gl_raster_t*)data;
@ -202,6 +203,9 @@ static void gl_render_msg(void *data, const char *msg, const struct font_params
y = params->y;
scale = params->scale;
full_screen = params->full_screen;
drop_x = params->drop_x;
drop_y = params->drop_y;
drop_mod = params->drop_mod;
color[0] = FONT_COLOR_GET_RED(params->color);
color[1] = FONT_COLOR_GET_GREEN(params->color);
@ -223,21 +227,27 @@ static void gl_render_msg(void *data, const char *msg, const struct font_params
color[1] = g_settings.video.msg_color_g;
color[2] = g_settings.video.msg_color_b;
color[3] = 1.0f;
}
color_dark[0] = color[0] * 0.3f;
color_dark[1] = color[1] * 0.3f;
color_dark[2] = color[2] * 0.3f;
color_dark[3] = color[3];
drop_x = -2;
drop_y = -2;
drop_mod = 0.3f;
}
gl_set_viewport(gl, gl->win_width, gl->win_height, full_screen, false);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendEquation(GL_FUNC_ADD);
// TODO: Make drop shadows parameterized?
render_message(font, msg, scale, color_dark,
x - scale * 2.0f / gl->vp.width, y - scale * 2.0f / gl->vp.height);
if (drop_x || drop_y)
{
color_dark[0] = color[0] * drop_mod;
color_dark[1] = color[1] * drop_mod;
color_dark[2] = color[2] * drop_mod;
color_dark[3] = color[3];
render_message(font, msg, scale, color_dark,
x + scale * drop_x / gl->vp.width, y + scale * drop_y / gl->vp.height);
}
render_message(font, msg, scale, color, x, y);
glDisable(GL_BLEND);