[ACCEPTED]-How do I use glutBitmapString() in C++ to draw text to the screen?-glut
Accepted answer
You have to use glRasterPos
to set the raster position 6 before calling glutBitmapString()
. Note that each call to 5 glutBitmapString()
advances the raster position, so several 4 consecutive calls will print out the strings 3 one after another. You can also set the 2 text color by using glColor()
. The set of available 1 fonts are listed here.
// Draw blue text at screen coordinates (100, 120), where (0, 0) is the top-left of the
// screen in an 18-point Helvetica font
glRasterPos2i(100, 120);
glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
glutBitmapString(GLUT_BITMAP_HELVETICA_18, "text to render");
Adding to Adam's answer,
glColor4f(0.0f, 0.0f, 1.0f, 1.0f); //RGBA values of text color
glRasterPos2i(100, 120); //Top left corner of text
const unsigned char* t = reinterpret_cast<const unsigned char *>("text to render");
// Since 2nd argument of glutBitmapString must be const unsigned char*
glutBitmapString(GLUT_BITMAP_HELVETICA_18,t);
Check out https://www.opengl.org/resources/libraries/glut/spec3/node76.html for more 1 font options
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.