不知道这是否有帮助,但我个人使用:
std::uint32_t Base = 0;
void SetupFonts(int FontSize)
{
HFONT Font = CreateFont(-MulDiv(FontSize, GetDeviceCaps(DC, LOGPIXELSY), 72), 0, 0, 0, FW_BOLD, false, false, false, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE | DEFAULT_PITCH, "Arial");
HFONT OldFont = static_cast<HFONT>(SelectObject(DC, Font));
wglUseFontBitmaps(DC, 32, 96, Base);
//wglUseFontBitmaps(DC, 32, 96, Base); //May or may not need this line twice.
SelectObject(DC, OldFont);
DeleteObject(Font);
}
template<typename... Args>
void Print(float X, float Y, float R, float G, float B, const char* Text, Args... args)
{
using namespace std;
std::size_t Position = 0;
std::string Container(Text);
std::vector<std::string> Arguments;
std::initializer_list<int> {(Arguments.push_back(to_string(args)), 0)...};
for (auto it = Arguments.begin(); it != Arguments.end(); ++it)
{
if ((Position = Container.find("%")) != std::string::npos)
{
Container.replace(Position, 1, *it);
}
}
glColor3f(R, G, B);
glRasterPos2f(X, Y);
glPushAttrib(GL_LIST_BIT);
glListBase(this->Base - 32);
glCallLists(Container.size(), GL_UNSIGNED_BYTE, Container.data());
glPopAttrib();
glFlush();
}
if (Base == 0) SetupFonts(12);
Print(200, 200, 1.0f, 0.0f, 0.0f, "Hello %", "World");
Print(200, 250, 0.0f, 1.0f, 0.0f, "Your FPS is: %", CalculateFPS());
ETC..
绘制如下所示的文本: