Reputation: 83
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 know the drawString() function for Graphics, but I am not sure if that is OK if I am using OpenGL. Is there a method from OpenGL that lets me easily print text to the screen?
Upvotes: 0
Views: 2404
Reputation: 1554
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.
Upvotes: 1
Reputation: 473407
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.
Upvotes: 0