如何使用 GLUT / OpenGL 绘图功能在屏幕上绘制文本字符串?
There are two ways to draw strings with GLUT
glutStrokeString will draw text in 3D
(source:uwa.edu.au )
and glutBitmapString will draw text facing the user
(source: sourceforge.net )
void RenderString(float x, float y, void *font, const char* string, RGB const& rgb)
{
char *c;
glColor3f(rgb.r, rgb.g, rgb.b);
glRasterPos2f(x, y);
glutBitmapString(font, string);
}
And you can call it like;
RenderString(0.0f, 0.0f, GLUT_BITMAP_TIMES_ROMAN_24, "Hello", RGB(1.0f, 0.0f, 0.0f));
If you don't like the built-in stroke font or bitmap font that comes with GLUT as per epatel's answer , you'll have to roll your own solution.
NeHe has some good tutorials (along with fully-working sample code) on this:
It's generally a bit nasty and not straightforward. Give this tool a try:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.