2.5
Nicer implementation of blurred font draw, moved to blenfont module. Set it with BLF_blur(value). Current kernels implemented are 3 and 5 only. Blenfont module can extend this once.
This commit is contained in:
parent
d2cc19dcc6
commit
6124933781
|
@ -68,6 +68,8 @@ float BLF_height(char *str);
|
||||||
*/
|
*/
|
||||||
void BLF_rotation(float angle);
|
void BLF_rotation(float angle);
|
||||||
void BLF_clipping(float xmin, float ymin, float xmax, float ymax);
|
void BLF_clipping(float xmin, float ymin, float xmax, float ymax);
|
||||||
|
void BLF_blur(int size);
|
||||||
|
|
||||||
|
|
||||||
void BLF_enable(int option);
|
void BLF_enable(int option);
|
||||||
void BLF_disable(int option);
|
void BLF_disable(int option);
|
||||||
|
|
|
@ -280,6 +280,15 @@ void BLF_size(int size, int dpi)
|
||||||
(*font->size_set)(font, size, dpi);
|
(*font->size_set)(font, size, dpi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BLF_blur(int size)
|
||||||
|
{
|
||||||
|
FontBLF *font;
|
||||||
|
|
||||||
|
font= global_font[global_font_cur];
|
||||||
|
if (font)
|
||||||
|
font->blur= size;
|
||||||
|
}
|
||||||
|
|
||||||
void BLF_draw(char *str)
|
void BLF_draw(char *str)
|
||||||
{
|
{
|
||||||
FontBLF *font;
|
FontBLF *font;
|
||||||
|
|
|
@ -433,6 +433,69 @@ void blf_glyph_free(GlyphBLF *g)
|
||||||
MEM_freeN(g);
|
MEM_freeN(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void blf_glyph_texture_draw(float uv[2][2], float dx, float y1, float dx1, float y2)
|
||||||
|
{
|
||||||
|
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glTexCoord2f(uv[0][0], uv[0][1]);
|
||||||
|
glVertex2f(dx, y1);
|
||||||
|
|
||||||
|
glTexCoord2f(uv[0][0], uv[1][1]);
|
||||||
|
glVertex2f(dx, y2);
|
||||||
|
|
||||||
|
glTexCoord2f(uv[1][0], uv[1][1]);
|
||||||
|
glVertex2f(dx1, y2);
|
||||||
|
|
||||||
|
glTexCoord2f(uv[1][0], uv[0][1]);
|
||||||
|
glVertex2f(dx1, y1);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void blf_glyph_texture5_draw(float uv[2][2], float x1, float y1, float x2, float y2)
|
||||||
|
{
|
||||||
|
float soft[25]= {
|
||||||
|
1/60.0f, 1/60.0f, 2/60.0f, 1/60.0f, 1/60.0f,
|
||||||
|
1/60.0f, 3/60.0f, 5/60.0f, 3/60.0f, 1/60.0f,
|
||||||
|
2/60.0f, 5/60.0f, 8/60.0f, 5/60.0f, 2/60.0f,
|
||||||
|
1/60.0f, 3/60.0f, 5/60.0f, 3/60.0f, 1/60.0f,
|
||||||
|
1/60.0f, 1/60.0f, 2/60.0f, 1/60.0f, 1/60.0f};
|
||||||
|
|
||||||
|
float color[4], *fp= soft;
|
||||||
|
int dx, dy;
|
||||||
|
|
||||||
|
glGetFloatv(GL_CURRENT_COLOR, color);
|
||||||
|
|
||||||
|
for(dx=-2; dx<3; dx++) {
|
||||||
|
for(dy=-2; dy<3; dy++, fp++) {
|
||||||
|
glColor4f(color[0], color[1], color[2], fp[0]*color[3]);
|
||||||
|
blf_glyph_texture_draw(uv, x1+dx, y1+dy, x2+dx, y2+dy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
glColor4fv(color);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void blf_glyph_texture3_draw(float uv[2][2], float x1, float y1, float x2, float y2)
|
||||||
|
{
|
||||||
|
float soft[9]= {1/16.0f, 2/16.0f, 1/16.0f, 2/16.0f, 4/16.0f, 2/16.0f, 1/16.0f, 2/16.0f, 1/16.0f};
|
||||||
|
float color[4], *fp= soft;
|
||||||
|
int dx, dy;
|
||||||
|
|
||||||
|
glGetFloatv(GL_CURRENT_COLOR, color);
|
||||||
|
|
||||||
|
for(dx=-1; dx<2; dx++) {
|
||||||
|
for(dy=-1; dy<2; dy++, fp++) {
|
||||||
|
glColor4f(color[0], color[1], color[2], fp[0]*color[3]);
|
||||||
|
blf_glyph_texture_draw(uv, x1+dx, y1+dy, x2+dx, y2+dy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
glColor4fv(color);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int blf_glyph_texture_render(FontBLF *font, GlyphBLF *g, float x, float y)
|
int blf_glyph_texture_render(FontBLF *font, GlyphBLF *g, float x, float y)
|
||||||
{
|
{
|
||||||
GlyphTextureBLF *gt;
|
GlyphTextureBLF *gt;
|
||||||
|
@ -461,20 +524,13 @@ int blf_glyph_texture_render(FontBLF *font, GlyphBLF *g, float x, float y)
|
||||||
if (cur_tex != gt->tex)
|
if (cur_tex != gt->tex)
|
||||||
glBindTexture(GL_TEXTURE_2D, gt->tex);
|
glBindTexture(GL_TEXTURE_2D, gt->tex);
|
||||||
|
|
||||||
glBegin(GL_QUADS);
|
if (font->blur==3)
|
||||||
glTexCoord2f(gt->uv[0][0], gt->uv[0][1]);
|
blf_glyph_texture3_draw(gt->uv, dx, y1, dx1, y2);
|
||||||
glVertex2f(dx, y1);
|
else if (font->blur==5)
|
||||||
|
blf_glyph_texture5_draw(gt->uv, dx, y1, dx1, y2);
|
||||||
glTexCoord2f(gt->uv[0][0], gt->uv[1][1]);
|
else
|
||||||
glVertex2f(dx, y2);
|
blf_glyph_texture_draw(gt->uv, dx, y1, dx1, y2);
|
||||||
|
|
||||||
glTexCoord2f(gt->uv[1][0], gt->uv[1][1]);
|
|
||||||
glVertex2f(dx1, y2);
|
|
||||||
|
|
||||||
glTexCoord2f(gt->uv[1][0], gt->uv[0][1]);
|
|
||||||
glVertex2f(dx1, y1);
|
|
||||||
glEnd();
|
|
||||||
|
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -157,7 +157,10 @@ typedef struct FontBLF {
|
||||||
|
|
||||||
/* angle in degrees. */
|
/* angle in degrees. */
|
||||||
float angle;
|
float angle;
|
||||||
|
|
||||||
|
/* blur: 3 or 5 large kernel */
|
||||||
|
int blur;
|
||||||
|
|
||||||
/* this is the matrix that we load before rotate/scale/translate. */
|
/* this is the matrix that we load before rotate/scale/translate. */
|
||||||
float mat[4][4];
|
float mat[4][4];
|
||||||
|
|
||||||
|
|
|
@ -134,53 +134,18 @@ static uiFont *uifont_to_blfont(int id)
|
||||||
|
|
||||||
/* *************** draw ************************ */
|
/* *************** draw ************************ */
|
||||||
|
|
||||||
|
static void ui_font_shadow_draw(uiFontStyle *fs, int x, int y, char *str)
|
||||||
static void ui_font_shadow5_draw(uiFontStyle *fs, int x, int y, char *str)
|
|
||||||
{
|
{
|
||||||
float soft[25]= {
|
float color[4];
|
||||||
1/60.0f, 1/60.0f, 2/60.0f, 1/60.0f, 1/60.0f,
|
|
||||||
1/60.0f, 3/60.0f, 5/60.0f, 3/60.0f, 1/60.0f,
|
|
||||||
2/60.0f, 5/60.0f, 8/60.0f, 5/60.0f, 2/60.0f,
|
|
||||||
1/60.0f, 3/60.0f, 5/60.0f, 3/60.0f, 1/60.0f,
|
|
||||||
1/60.0f, 1/60.0f, 2/60.0f, 1/60.0f, 1/60.0f};
|
|
||||||
|
|
||||||
float color[4], *fp= soft;
|
|
||||||
int dx, dy;
|
|
||||||
|
|
||||||
glGetFloatv(GL_CURRENT_COLOR, color);
|
glGetFloatv(GL_CURRENT_COLOR, color);
|
||||||
|
|
||||||
x+= fs->shadx;
|
glColor4f(fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fs->shadowalpha);
|
||||||
y+= fs->shady;
|
|
||||||
|
|
||||||
for(dx=-2; dx<3; dx++) {
|
BLF_blur(fs->shadow);
|
||||||
for(dy=-2; dy<3; dy++, fp++) {
|
BLF_position(x+fs->shadx, y+fs->shady, 0.0f);
|
||||||
glColor4f(fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fp[0]*fs->shadowalpha);
|
BLF_draw(str);
|
||||||
BLF_position(x+dx, y+dy, 0.0f);
|
BLF_blur(0);
|
||||||
BLF_draw(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
glColor4fv(color);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ui_font_shadow3_draw(uiFontStyle *fs, int x, int y, char *str)
|
|
||||||
{
|
|
||||||
float soft[9]= {1/16.0f, 2/16.0f, 1/16.0f, 2/16.0f, 4/16.0f, 2/16.0f, 1/16.0f, 2/16.0f, 1/16.0f};
|
|
||||||
float color[4], *fp= soft;
|
|
||||||
int dx, dy;
|
|
||||||
|
|
||||||
glGetFloatv(GL_CURRENT_COLOR, color);
|
|
||||||
|
|
||||||
x+= fs->shadx;
|
|
||||||
y+= fs->shady;
|
|
||||||
|
|
||||||
for(dx=-1; dx<2; dx++) {
|
|
||||||
for(dy=-1; dy<2; dy++, fp++) {
|
|
||||||
glColor4f(fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fp[0]*fs->shadowalpha);
|
|
||||||
BLF_position(x+dx, y+dy, 0.0f);
|
|
||||||
BLF_draw(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
glColor4fv(color);
|
glColor4fv(color);
|
||||||
}
|
}
|
||||||
|
@ -204,10 +169,8 @@ void uiStyleFontDraw(uiFontStyle *fs, rcti *rect, char *str)
|
||||||
BLF_clipping(rect->xmin-4, rect->ymin-4, rect->xmax+4, rect->ymax+4);
|
BLF_clipping(rect->xmin-4, rect->ymin-4, rect->xmax+4, rect->ymax+4);
|
||||||
BLF_enable(BLF_CLIPPING);
|
BLF_enable(BLF_CLIPPING);
|
||||||
|
|
||||||
if(fs->shadow==3)
|
if(fs->shadow)
|
||||||
ui_font_shadow3_draw(fs, rect->xmin+xofs, rect->ymin+yofs, str);
|
ui_font_shadow_draw(fs, rect->xmin+xofs, rect->ymin+yofs, str);
|
||||||
else if(fs->shadow==5)
|
|
||||||
ui_font_shadow5_draw(fs, rect->xmin+xofs, rect->ymin+yofs, str);
|
|
||||||
|
|
||||||
BLF_position(rect->xmin+xofs, rect->ymin+yofs, 0.0f);
|
BLF_position(rect->xmin+xofs, rect->ymin+yofs, 0.0f);
|
||||||
BLF_draw(str);
|
BLF_draw(str);
|
||||||
|
|
Loading…
Reference in New Issue