diff options
author | Mike Erwin <significant.bit@gmail.com> | 2017-02-02 00:01:25 +0300 |
---|---|---|
committer | Mike Erwin <significant.bit@gmail.com> | 2017-02-02 00:21:08 +0300 |
commit | ba551014f8fc115b0d816d6d399022a897953059 (patch) | |
tree | 83502f0970a0d9f457560ccaeba6871f06b3b08a /source/blender/blenfont/intern | |
parent | 13399d471e5a86081de7aba031043ce8f0578fdf (diff) |
add BLF_color functions
Needed a way to pass main font color to BLF without using obsolete glColor. Could not use immUniform since BLF binds its shader internally.
Diffstat (limited to 'source/blender/blenfont/intern')
-rw-r--r-- | source/blender/blenfont/intern/blf.c | 68 |
1 files changed, 64 insertions, 4 deletions
diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c index 1ce4753cc39..58c6f095ae7 100644 --- a/source/blender/blenfont/intern/blf.c +++ b/source/blender/blenfont/intern/blf.c @@ -466,6 +466,70 @@ void BLF_blur(int fontid, int size) } #endif +void BLF_color4ubv(int fontid, const unsigned char rgba[4]) +{ + FontBLF *font = blf_get(fontid); + + if (font) { + font->color[0] = rgba[0]; + font->color[1] = rgba[1]; + font->color[2] = rgba[2]; + font->color[3] = rgba[3]; + } +} + +void BLF_color3ubv_alpha(int fontid, const unsigned char rgb[3], unsigned char alpha) +{ + FontBLF *font = blf_get(fontid); + + if (font) { + font->color[0] = rgb[0]; + font->color[1] = rgb[1]; + font->color[2] = rgb[2]; + font->color[3] = alpha; + } +} + +void BLF_color3ubv(int fontid, const unsigned char rgb[3]) +{ + BLF_color3ubv_alpha(fontid, rgb, 255); +} + +void BLF_color3ub(int fontid, unsigned char r, unsigned char g, unsigned char b) +{ + FontBLF *font = blf_get(fontid); + + if (font) { + font->color[0] = r; + font->color[1] = g; + font->color[2] = b; + font->color[3] = 255; + } +} + +void BLF_color4fv(int fontid, const float rgba[4]) +{ + FontBLF *font = blf_get(fontid); + + if (font) { + rgba_float_to_uchar(font->color, rgba); + } +} + +void BLF_color3fv_alpha(int fontid, const float rgb[3], float alpha) +{ + float rgba[4]; + copy_v3_v3(rgba, rgb); + rgba[3] = alpha; + BLF_color4fv(fontid, rgba); +} + +void BLF_color3f(int fontid, float r, float g, float b) +{ + float rgba[4] = { r, g, b, 1.0f }; + BLF_color4fv(fontid, rgba); +} + void BLF_draw_default(float x, float y, float z, const char *str, size_t len) { ASSERT_DEFAULT_SET; @@ -517,10 +581,6 @@ static void blf_draw_gl__start(FontBLF *font) if (font->flags & BLF_ROTATION) /* radians -> degrees */ gpuRotateAxis(RAD2DEG(font->angle), 'Z'); - float temp_color[4]; - glGetFloatv(GL_CURRENT_COLOR, temp_color); /* TODO(merwin): new BLF_color function? */ - rgba_float_to_uchar(font->color, temp_color); - #ifndef BLF_STANDALONE VertexFormat *format = immVertexFormat(); unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT); |