How to draw a String to the window with OpenGL?

后端 未结 2 408
渐次进展
渐次进展 2020-12-22 07:50

I\'m creating a game but I have one problem: how can I draw text to the screen, as I want to print something every time the player picks up something or gets hurt. I already

相关标签:
2条回答
  • 2020-12-22 08:30

    No, there is no method in OpenGL for easily printing text. You must either use one of the libraries that exist for this purpose or you must write it yourself.

    0 讨论(0)
  • 2020-12-22 08:49

    In OpenGL there is no function / method you can call to render text to the screen.

    You have two choices: either 1) use a library; or 2) roll your own, creating your own calls to render text to the display.

    1) There are a number of different libraries out there that you could use to render text to the display; however the most obvious and accessible to you is within GLUT. There are two calls within that you could use:

    glutBitmapString() and glutStrokeString()
    

    The first of these will render text to the display in what I guess could be referred to as a 2d manner (looking like it's pasted right of the display). The latter with display 3d text.

    You can refer to

    http://freeglut.sourceforge.net/docs/api.php
    

    for API references.

    2) You could create a function / method that renders character textures to the display using the standard OpenGL functions, or you could potentially use stencil buffers using calls to glDrawPixels() to generate the characters.

    I haven't tried these: I'm just thinking off the top of my head so you're mileage may vary. Good luck.

    0 讨论(0)
提交回复
热议问题