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

后端 未结 4 1300
遇见更好的自我
遇见更好的自我 2020-11-30 02:34

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

相关标签:
4条回答
  • 2020-11-30 02:56

    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)

    0 讨论(0)
  • 2020-11-30 02:56

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

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

    0 讨论(0)
  • 2020-11-30 03:04

    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
    0 讨论(0)
  • 2020-11-30 03:13
    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));
    
    0 讨论(0)
提交回复
热议问题