From 447dd3c9597dd91b5229437e43a27a0fa26b6a53 Mon Sep 17 00:00:00 2001 From: Rob Haarsma Date: Thu, 15 May 2003 17:01:00 +0000 Subject: Seeing all comments on the interface slowdown, I decided to try a different approach for the coloring of interface texts. Currently two seperate fonts get generated, one black and one white, which eliminates the glPixelTransfer command. (which assumably caused the huge slowdowns) Please try, and post your experiences on the interface drawing speed. NOTE: for this new method you need the *unmodified* FTGL library: http://homepages.paradise.net.nz/henryj/code/#FTGL Apologies on any inconveniences... --- source/blender/ftfont/intern/FTF_TTFont.cpp | 61 ++++++++++++++++------------- source/blender/ftfont/intern/FTF_TTFont.h | 3 +- 2 files changed, 36 insertions(+), 28 deletions(-) (limited to 'source/blender/ftfont') diff --git a/source/blender/ftfont/intern/FTF_TTFont.cpp b/source/blender/ftfont/intern/FTF_TTFont.cpp index a9f4408f58a..f0979e4fdd8 100644 --- a/source/blender/ftfont/intern/FTF_TTFont.cpp +++ b/source/blender/ftfont/intern/FTF_TTFont.cpp @@ -107,7 +107,7 @@ FTF_TTFont::FTF_TTFont(void) char *bundlepath; #endif - font=NULL; + fontB = fontW =NULL; font_size=FONT_SIZE_DEFAULT; strcpy(encoding_name, SYSTEM_ENCODING_DEFAULT); @@ -145,7 +145,8 @@ FTF_TTFont::FTF_TTFont(void) FTF_TTFont::~FTF_TTFont(void) { - if (font) delete font; + if (fontB) delete fontB; + if (fontW) delete fontW; } @@ -154,19 +155,26 @@ int FTF_TTFont::SetFont(char* str, int size) int err = 0; bool success = 0; - delete font; + if(fontB) delete fontB; + if(fontW) delete fontW; - font = new FTGLPixmapFont(str); - err = font->Error(); + fontB = new FTGLPixmapFont(str); + fontW = new FTGLPixmapFont(str); + err = fontB->Error(); if(err) { // printf("Failed to open font %s\n", str); return 0; } else { - success = font->FaceSize(size); + success = fontB->FaceSize(size); + if(!success) return 0; + success = fontW->FaceSize(size); + if(!success) return 0; + + success = fontB->CharMap(ft_encoding_unicode); if(!success) return 0; - success = font->CharMap(ft_encoding_unicode); + success = fontW->CharMap(ft_encoding_unicode); if(!success) return 0; return 1; @@ -212,7 +220,8 @@ void FTF_TTFont::SetEncoding(char* str) void FTF_TTFont::SetSize(int size) { - font->FaceSize(size); + fontB->FaceSize(size); + fontW->FaceSize(size); font_size = size; } @@ -223,12 +232,12 @@ int FTF_TTFont::GetSize(void) int FTF_TTFont::Ascender(void) { - return font->Ascender(); + return fontB->Ascender(); } int FTF_TTFont::Descender(void) { - return font->Descender(); + return fontB->Descender(); } @@ -249,20 +258,14 @@ float FTF_TTFont::DrawString(char* str, unsigned int flag, int select) len=utf8towchar(wstr,str); if(!select) { - glPixelTransferf(GL_RED_SCALE, 0.0); - glPixelTransferf(GL_GREEN_SCALE, 0.0); - glPixelTransferf(GL_BLUE_SCALE, 0.0); - } - - font->Render(wstr); - - if(!select) { - glPixelTransferf(GL_RED_SCALE, 1.0); - glPixelTransferf(GL_GREEN_SCALE, 1.0); - glPixelTransferf(GL_BLUE_SCALE, 1.0); + glColor4f(0.0, 0.0, 0.0, 1.0); + fontB->Render(wstr); + return fontB->Advance(wstr); + } else { + glColor4f(1.0, 1.0, 1.0, 1.0); + fontW->Render(wstr); + return fontW->Advance(wstr); } - - return font->Advance(wstr); } @@ -276,17 +279,19 @@ float FTF_TTFont::DrawStringRGB(char* str, unsigned int flag, float r, float g, else len=utf8towchar(wstr,str); + glColor4f(1.0, 1.0, 1.0, 1.0); + glPixelTransferf(GL_RED_SCALE, r); glPixelTransferf(GL_GREEN_SCALE, g); glPixelTransferf(GL_BLUE_SCALE, b); - font->Render(wstr); + fontW->Render(wstr); glPixelTransferf(GL_RED_SCALE, 1.0); glPixelTransferf(GL_GREEN_SCALE, 1.0); glPixelTransferf(GL_BLUE_SCALE, 1.0); - return font->Advance(wstr); + return fontW->Advance(wstr); } @@ -300,7 +305,8 @@ float FTF_TTFont::GetStringWidth(char* str, unsigned int flag) else len=utf8towchar(wstr,str); - return font->Advance(wstr); + glColor4f(0.0, 0.0, 0.0, 1.0); + return fontB->Advance(wstr); } @@ -314,6 +320,7 @@ void FTF_TTFont::GetBoundingBox(char* str, float *llx, float *lly, float *llz, f else len=utf8towchar(wstr,str); - font->BBox(wstr, *llx, *lly, *llz, *urx, *ury, *urz); + glColor4f(0.0, 0.0, 0.0, 1.0); + fontB->BBox(wstr, *llx, *lly, *llz, *urx, *ury, *urz); } diff --git a/source/blender/ftfont/intern/FTF_TTFont.h b/source/blender/ftfont/intern/FTF_TTFont.h index 9492e326a7e..4e0e5ae7ff1 100644 --- a/source/blender/ftfont/intern/FTF_TTFont.h +++ b/source/blender/ftfont/intern/FTF_TTFont.h @@ -99,7 +99,8 @@ protected: int font_size; /** FTGL's */ - FTFont* font; + FTFont* fontB; + FTFont* fontW; /** from system encoding in .locale to UNICODE */ // iconv_t cd; -- cgit v1.2.3