From 79822b6c89a373ee9bccc3ffb0df0cb8c18f6f34 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 16 Aug 2010 21:40:12 +0000 Subject: [PATCH] Improve the text appearance using an outline. --- src/debugfps.cpp | 6 +++--- src/font.cpp | 41 ++++++++++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/debugfps.cpp b/src/debugfps.cpp index fab2b7fa..5517463c 100644 --- a/src/debugfps.cpp +++ b/src/debugfps.cpp @@ -58,17 +58,17 @@ void DebugFps::TickRender(float delta_time) sprintf(buf, "Game % 7.2f % 7.2f", 1e3f * Profiler::GetMean(Profiler::STAT_TICK_GAME), 1e3f * Profiler::GetMax(Profiler::STAT_TICK_GAME)); - data->font->PrintBold(10, 28, buf); + data->font->PrintBold(10, 34, buf); sprintf(buf, "Render % 7.2f % 7.2f", 1e3f * Profiler::GetMean(Profiler::STAT_TICK_RENDER), 1e3f * Profiler::GetMax(Profiler::STAT_TICK_RENDER)); - data->font->PrintBold(10, 46, buf); + data->font->PrintBold(10, 50, buf); sprintf(buf, "Blit % 7.2f % 7.2f", 1e3f * Profiler::GetMean(Profiler::STAT_TICK_BLIT), 1e3f * Profiler::GetMax(Profiler::STAT_TICK_BLIT)); - data->font->PrintBold(10, 64, buf); + data->font->PrintBold(10, 66, buf); sprintf(buf, "Frame % 7.2f % 7.2f", 1e3f * Profiler::GetMean(Profiler::STAT_TICK_FRAME), diff --git a/src/font.cpp b/src/font.cpp index 62373ae6..9b491faf 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -104,14 +104,17 @@ void Font::Print(int x, int y, char const *str) float tx = .0625f * (ch & 0xf); float ty = .0625f * ((ch >> 4) & 0xf); - glTexCoord2f(tx, ty); - glVertex2f(x, y); - glTexCoord2f(tx + .0625f, ty); - glVertex2f(x + w, y); - glTexCoord2f(tx + .0625f, ty + .0625f); - glVertex2f(x + w, y + h); - glTexCoord2f(tx, ty + .0625f); - glVertex2f(x, y + h); + if (ch != ' ') + { + glTexCoord2f(tx, ty); + glVertex2f(x, y); + glTexCoord2f(tx + .0625f, ty); + glVertex2f(x + w, y); + glTexCoord2f(tx + .0625f, ty + .0625f); + glVertex2f(x + w, y + h); + glTexCoord2f(tx, ty + .0625f); + glVertex2f(x, y + h); + } x += w; } @@ -120,8 +123,24 @@ void Font::Print(int x, int y, char const *str) void Font::PrintBold(int x, int y, char const *str) { - Print(x, y, str); - Print(x + 1, y, str); - Print(x, y + 1, str); + static struct { int dx, dy; float r, g, b; } tab[] = + { + { -1, 0, 0.0, 0.0, 0.0 }, + { 0, -1, 0.0, 0.0, 0.0 }, + { 0, 1, 0.0, 0.0, 0.0 }, + { 1, -1, 0.0, 0.0, 0.0 }, + { 1, 1, 0.0, 0.0, 0.0 }, + { 2, 0, 0.0, 0.0, 0.0 }, + { 1, 0, 0.5, 0.5, 0.5 }, + { 0, 0, 1.0, 1.0, 1.0 }, + }; + + glPushAttrib(GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT); + for (unsigned int i = 0; i < sizeof(tab) / sizeof(*tab); i++) + { + glColor3f(tab[i].r, tab[i].g, tab[i].b); + Print(x + tab[i].dx, y + tab[i].dy, str); + } + glPopAttrib(); }