diff options
author | Diego Borghetti <bdiego@gmail.com> | 2009-04-06 08:12:31 +0400 |
---|---|---|
committer | Diego Borghetti <bdiego@gmail.com> | 2009-04-06 08:12:31 +0400 |
commit | e430816cde23a549e2779d815339bf685c54558f (patch) | |
tree | c1e1d654792367e4a1335d71a05abe69d6081cb9 /source/blender | |
parent | c99b9d792282fd371e0a8e5a91cebb0d272e3cf4 (diff) |
Add back bitmap draw mode, right now only internal font, tomorrow
freetype2.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenfont/BLF_api.h | 4 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf.c | 42 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_font.c | 1 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_internal.c | 48 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_internal_types.h | 3 |
5 files changed, 81 insertions, 17 deletions
diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index 71554df57ab..a5c4e037a2d 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -91,4 +91,8 @@ void BLF_dir_free(char **dirs, int count); #define BLF_ROTATION (1<<0) #define BLF_CLIPPING (1<<1) +/* font->mode. */ +#define BLF_MODE_TEXTURE 0 +#define BLF_MODE_BITMAP 1 + #endif /* BLF_API_H */ diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c index 8e3b27bb425..b04e0efe94a 100644 --- a/source/blender/blenfont/intern/blf.c +++ b/source/blender/blenfont/intern/blf.c @@ -286,22 +286,31 @@ void BLF_draw(char *str) font= global_font[global_font_cur]; if (font && font->draw) { - glEnable(GL_BLEND); - glEnable(GL_TEXTURE_2D); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + if (font->mode == BLF_MODE_BITMAP) { + /* the pixmap alignment is handle + * in BLF_position (old ui_rasterpos_safe). + */ + glRasterPos3f(font->pos[0], font->pos[1], font->pos[2]); + (*font->draw)(font, str); + } + else { + glEnable(GL_BLEND); + glEnable(GL_TEXTURE_2D); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glPushMatrix(); - glTranslatef(font->pos[0], font->pos[1], font->pos[2]); - glScalef(font->aspect, font->aspect, 1.0); + glPushMatrix(); + glTranslatef(font->pos[0], font->pos[1], font->pos[2]); + glScalef(font->aspect, font->aspect, 1.0); - if (font->flags & BLF_ROTATION) - glRotatef(font->angle, 0.0f, 0.0f, 1.0f); + if (font->flags & BLF_ROTATION) + glRotatef(font->angle, 0.0f, 0.0f, 1.0f); - (*font->draw)(font, str); + (*font->draw)(font, str); - glPopMatrix(); - glDisable(GL_BLEND); - glDisable(GL_TEXTURE_2D); + glPopMatrix(); + glDisable(GL_BLEND); + glDisable(GL_TEXTURE_2D); + } } } @@ -355,3 +364,12 @@ void BLF_clipping(float xmin, float ymin, float xmax, float ymax) font->clip_rec.ymax= ymax; } } + +void BLF_mode(int mode) +{ + FontBLF *font; + + font= global_font[global_font_cur]; + if (font) + font->mode= mode; +} diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index d5c6ae5b359..3e17b26bc6c 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -274,6 +274,7 @@ void blf_font_free(FontBLF *font) void blf_font_fill(FontBLF *font) { font->type= BLF_FONT_FREETYPE2; + font->mode= BLF_MODE_TEXTURE; font->ref= 1; font->aspect= 1.0f; font->pos[0]= 0.0f; diff --git a/source/blender/blenfont/intern/blf_internal.c b/source/blender/blenfont/intern/blf_internal.c index 8ba88d054a5..04968f05ded 100644 --- a/source/blender/blenfont/intern/blf_internal.c +++ b/source/blender/blenfont/intern/blf_internal.c @@ -144,7 +144,7 @@ void blf_internal_size(FontBLF *font, int size, int dpi) return; } -void blf_internal_draw(FontBLF *font, char *str) +void blf_internal_texture_draw(FontBLF *font, char *str) { FontDataBLF *data; CharDataBLF *cd; @@ -207,6 +207,41 @@ void blf_internal_draw(FontBLF *font, char *str) } } +void blf_internal_bitmap_draw(FontBLF *font, char *str) +{ + FontDataBLF *data; + CharDataBLF *cd; + unsigned char c; + GLint alignment; + + data= (FontDataBLF *)font->engine; + + glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + while ((c= (unsigned char) *str++)) { + cd= &data->chars[c]; + + if (cd->data_offset==-1) { + GLubyte nullBitmap= 0; + glBitmap(1, 1, 0, 0, cd->advance, 0, &nullBitmap); + } else { + GLubyte *bitmap= &data->bitmap_data[cd->data_offset]; + glBitmap(cd->width, cd->height, cd->xorig, cd->yorig, cd->advance, 0, bitmap); + } + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); +} + +void blf_internal_draw(FontBLF *font, char *str) +{ + if (font->mode == BLF_MODE_BITMAP) + blf_internal_bitmap_draw(font, str); + else + blf_internal_texture_draw(font, str); +} + void blf_internal_boundbox(FontBLF *font, char *str, rctf *box) { FontDataBLF *data; @@ -313,6 +348,7 @@ FontBLF *blf_internal_new(char *name) font->type= BLF_FONT_INTERNAL; font->ref= 1; + font->mode= BLF_MODE_TEXTURE; font->aspect= 1.0f; font->pos[0]= 0.0f; font->pos[1]= 0.0f; @@ -336,10 +372,12 @@ FontBLF *blf_internal_new(char *name) font->height_get= blf_internal_height; font->free= blf_internal_free; - if (blf_internal_get_texture(font) != 0) { - MEM_freeN(font->name); - MEM_freeN(font); - return(NULL); + if (font->mode == BLF_MODE_TEXTURE) { + if (blf_internal_get_texture(font) != 0) { + MEM_freeN(font->name); + MEM_freeN(font); + return(NULL); + } } return(font); diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h index 49d8cc2e692..dba4c34c6bb 100644 --- a/source/blender/blenfont/intern/blf_internal_types.h +++ b/source/blender/blenfont/intern/blf_internal_types.h @@ -123,6 +123,9 @@ typedef struct FontBLF { /* font type, can be freetype2 or internal. */ int type; + /* draw mode, texture or bitmap. */ + int mode; + /* reference count. */ int ref; |