简体   繁体   English

如何在 C++ 中使用 GLUT/OpenGL 绘制文本?

[英]How do I draw text with GLUT / OpenGL in C++?

如何使用 GLUT / OpenGL 绘图功能在屏幕上绘制文本字符串?

There are two ways to draw strings with GLUT用 GLUT 绘制字符串有两种方法

glutStrokeString will draw text in 3D glutStrokeString将在 3D 中绘制文本

替代文字
(source:uwa.edu.au ) (来源:uwa.edu.au

and glutBitmapString will draw text facing the userglutBitmapString将绘制面向用户的文本

替代文字
(source: sourceforge.net ) (来源: 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.如果您不喜欢根据epatel 的回答随 GLUT 一起提供的内置笔划字体或位图字体,则必须推出自己的解决方案。

NeHe has some good tutorials (along with fully-working sample code) on this: NeHe 在这方面有一些很好的教程(以及完整的示例代码):

It's generally a bit nasty and not straightforward.它通常有点讨厌,并不简单。 Give this tool a try:试试这个工具:

http://students.cs.byu.edu/~bfish/glfontdl.php http://students.cs.byu.edu/~bfish/glfontdl.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM