From ebd5bca7fe8a227af1fd801f2df2e4d874b2fdb8 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 28 Jun 2011 06:18:24 +0000 Subject: [PATCH] - attempt to fix 'blurry fonts' --- source/glest_game/global/core_data.cpp | 5 ++++- source/glest_game/graphics/renderer.cpp | 4 ++-- source/shared_lib/include/graphics/font.h | 1 + source/shared_lib/sources/graphics/font.cpp | 1 + .../sources/graphics/gl/font_textFTGL.cpp | 5 +++++ .../sources/graphics/gl/text_renderer_gl.cpp | 18 ++++++++++++++++-- 6 files changed, 29 insertions(+), 5 deletions(-) diff --git a/source/glest_game/global/core_data.cpp b/source/glest_game/global/core_data.cpp index a5c2f118..c2b2ee3f 100644 --- a/source/glest_game/global/core_data.cpp +++ b/source/glest_game/global/core_data.cpp @@ -334,7 +334,10 @@ int CoreData::computeFontSize(int size) { rs = size * screenH / 1024; } else { - rs = ((float)size * 0.80); + if(Renderer::renderText3DEnabled) { + //rs = ((float)size * 0.85); + //rs = 24; + } //int screenH = config.getInt("ScreenHeight"); //rs = size * screenH / 1024; diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 81a9cd96..377495c2 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -1440,13 +1440,13 @@ void Renderer::renderText(const string &text, Font2D *font, float alpha, int x, } Vec2f Renderer::getCentered3DPos(const string &text, Font3D *font, Vec2f &pos, int w, int h) { - float lineWidth = font->getTextHandler()->Advance(text.c_str()); + float lineWidth = (font->getTextHandler()->Advance(text.c_str()) * Font::scaleFontValue); if(lineWidth < w) { pos.x += ((w / 2.f) - (lineWidth / 2.f)); } //h /= 2.f; - float lineHeight = font->getTextHandler()->LineHeight(text.c_str()); + float lineHeight = (font->getTextHandler()->LineHeight(text.c_str()) * Font::scaleFontValue); if(lineHeight < h) { //pos.y += ((float)h / 2.f); //pos.y -= ((float(h) / 2.f) - (lineHeight / 2.f)); diff --git a/source/shared_lib/include/graphics/font.h b/source/shared_lib/include/graphics/font.h index 74ac2934..3e564aba 100644 --- a/source/shared_lib/include/graphics/font.h +++ b/source/shared_lib/include/graphics/font.h @@ -65,6 +65,7 @@ public: static bool fontIsMultibyte; static bool forceLegacyFonts; static bool fontIsRightToLeft; + static float scaleFontValue; public: enum Width { diff --git a/source/shared_lib/sources/graphics/font.cpp b/source/shared_lib/sources/graphics/font.cpp index 87de94fa..ba10a3fd 100644 --- a/source/shared_lib/sources/graphics/font.cpp +++ b/source/shared_lib/sources/graphics/font.cpp @@ -38,6 +38,7 @@ bool Font::fontIsMultibyte = false; bool Font::forceLegacyFonts = false; float FontMetrics::DEFAULT_Y_OFFSET_FACTOR = 8.0f; bool Font::fontIsRightToLeft = false; +float Font::scaleFontValue = 0.65; // // ===================================================== diff --git a/source/shared_lib/sources/graphics/gl/font_textFTGL.cpp b/source/shared_lib/sources/graphics/gl/font_textFTGL.cpp index 50343072..2bc113a0 100644 --- a/source/shared_lib/sources/graphics/gl/font_textFTGL.cpp +++ b/source/shared_lib/sources/graphics/gl/font_textFTGL.cpp @@ -121,6 +121,11 @@ void TextFTGL::init(string fontName, int fontSize) { } else if(type == ftht_3D) { ftFont = new FTGLTextureFont(fontFile); + + //ftFont = new FTBufferFont(fontFile); + //ftFont = new FTGLExtrdFont(fontFile); + //ftFont = new FTGLPolygonFont("/usr/share/fonts/truetype/arphic/uming.ttc"); + //printf("3D font [%s]\n",fontFile); } else { diff --git a/source/shared_lib/sources/graphics/gl/text_renderer_gl.cpp b/source/shared_lib/sources/graphics/gl/text_renderer_gl.cpp index cd532548..fbe7cd33 100644 --- a/source/shared_lib/sources/graphics/gl/text_renderer_gl.cpp +++ b/source/shared_lib/sources/graphics/gl/text_renderer_gl.cpp @@ -435,7 +435,7 @@ void TextRenderer3DGl::internalRender(const string &text, float x, float y, boo const unsigned char *utext= NULL; //assertGl(); - glMatrixMode(GL_MODELVIEW); + //glMatrixMode(GL_TEXTURE); //assertGl(); @@ -518,18 +518,28 @@ void TextRenderer3DGl::internalRender(const string &text, float x, float y, boo //assertGl(); + float scaleX = Font::scaleFontValue; + float scaleY = Font::scaleFontValue; + float scaleZ = 1.0; + + //int scaleWidthX = (font->getTextHandler()->Advance(renderText.c_str()) * scaleX) / 2.0; + //glTranslatef(translatePos.x + scaleWidthX, translatePos.y, translatePos.z); glTranslatef(translatePos.x, translatePos.y, translatePos.z); //assertGl(); //glScalef(scaleX, scaleY, scaleZ); + + //glTranslatef(0.45, 0.45, 1.0); + //assertGl(); // font->getTextHandler()->Render(text.c_str()); // specialFTGLErrorCheckWorkaround(text); if(font->getTextHandler() != NULL) { + glScalef(scaleX, scaleY, scaleZ); if(text.find("\n") == renderText.npos && renderText.find("\t") == renderText.npos) { //assertGl(); font->getTextHandler()->Render(renderText.c_str()); @@ -577,7 +587,7 @@ void TextRenderer3DGl::internalRender(const string &text, float x, float y, boo { line++; //assertGl(); - float yLineValue = font->getTextHandler()->LineHeight(parts[i].c_str()); + float yLineValue = (font->getTextHandler()->LineHeight(parts[i].c_str()) * Font::scaleFontValue); //assertGl(); translatePos= Vec3f(translatePos.x, translatePos.y - yLineValue, translatePos.z); needsRecursiveRender = true; @@ -589,6 +599,7 @@ void TextRenderer3DGl::internalRender(const string &text, float x, float y, boo glPushMatrix(); glLoadIdentity(); glTranslatef(translatePos.x, translatePos.y, translatePos.z); + glScalef(scaleX, scaleY, scaleZ); font->getTextHandler()->Render(parts[i].c_str()); specialFTGLErrorCheckWorkaround(parts[i]); glPopMatrix(); @@ -646,6 +657,9 @@ void TextRenderer3DGl::internalRender(const string &text, float x, float y, boo glPopAttrib(); } + //assertGl(); + //glDisable(GL_TEXTURE_2D); + assertGl(); }