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





Shouldn't you advance the position on screen with each character printed (i.e. move the glRasterPos3f inside the for loop in glutBitmapCharacter?
– orhtej2
Sep 2 at 18:11


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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)