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

狂风中的少年 提交于 2019-11-26 15:46:45

问题


How do I draw a text string onto the screen using GLUT / OpenGL drawing functions?


回答1:


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)




回答2:


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:

  • Lesson 13 - Bitmap Fonts
  • Lesson 14 - Outline Fonts
  • Lesson 15 - Texture-Mapped Outline Fonts



回答3:


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));



回答4:


It's generally a bit nasty and not straightforward. Give this tool a try:

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



来源:https://stackoverflow.com/questions/538661/how-do-i-draw-text-with-glut-opengl-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!