Browse Source

Improve the text appearance using an outline.

legacy
Sam Hocevar sam 14 years ago
parent
commit
79822b6c89
2 changed files with 33 additions and 14 deletions
  1. +3
    -3
      src/debugfps.cpp
  2. +30
    -11
      src/font.cpp

+ 3
- 3
src/debugfps.cpp View File

@@ -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),


+ 30
- 11
src/font.cpp View File

@@ -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();
}


Loading…
Cancel
Save