Displaying text in the corner in OpenGL
Displaying text in the corner in OpenGL
So recently i tried to do some displaying text in openGl, but i can make it appear
void renderBitmapString(float x, float y, char* text)
char *c;
glRasterPos3f(x, y, 6.0f);
for (c = text; *c != ''; c++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, *c);
void Draw()
glPushMatrix();
float m_amb = 1.0f, 1.0f, 1.0f, 1.0f ;
float m_dif = 1.0f, 1.0f, 1.0f, 1.0f ;
float m_spe = 0.0f, 0.0f, 0.0f, 1.0f ;
glMaterialfv(GL_FRONT, GL_AMBIENT, m_amb);
glMaterialfv(GL_FRONT, GL_DIFFUSE, m_dif);
glMaterialfv(GL_FRONT, GL_SPECULAR, m_spe);
glBegin(GL_QUADS);
glNormal3f(0.0f, 0.0f, 1.0f);
glVertex3f(place.x -5.0f, place.y -5.0f, place.z + 5.0f);
glNormal3f(0.0f, 0.0f, 1.0f);
glVertex3f(place.x + 5.0f, place.y - 5.0f, place.z + 5.0f);
glNormal3f(0.0f, 0.0f, 1.0f);
glVertex3f(place.x + 5.0f, place.y + 5.0f, place.z + 5.0f);
glNormal3f(0.0f, 0.0f, 1.0f);
glVertex3f(place.x - 5.0f, place.y + 5.0f, place.z + 5.0f);
glEnd();
char text[50];
sprintf(text, "test");
glColor3f(1, 1, 1);
renderBitmapString(90, 95, text);
glEnable(GL_LIGHTING);
glEnable(GL_CULL_FACE);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
It should render a plane and 'test' in the corner, but only plane is showing. Draw() is a public function in class Menu, while renderBitmapString is global function
glRasterPos3f
for
glutBitmapCharacter
This answer suggest using
glWindowPos
instead of glRasterPos
.– orhtej2
Sep 2 at 18:14
glWindowPos
glRasterPos
What is the window size respectively the viewport
glViewport
. What is the projection matrix and the model view matrix? Please read How to create a Minimal, Complete, and Verifiable example. Note, the z coordinate of the text is 6.0f. Is this in between the near and far plane? Is the text even on the viewport (in clip space) or is it outside at the top right?– Rabbid76
Sep 2 at 18:19
glViewport
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Shouldn't you advance the position on screen with each character printed (i.e. move the
glRasterPos3f
inside thefor
loop inglutBitmapCharacter
?– orhtej2
Sep 2 at 18:11