OpenGL text problem

Started by
18 comments, last by Deception666 18 years, 5 months ago
Use glOrtho only at the end before rendering text. Use the gluLookAt before to render the scene.
Advertisement
Alright - got it. Now, how do i keep the text in the bottom left corner of the screen at all times. The camera can rotate by the mouse or keys, and go forward and back, and throughout all of this, i would like for the text to stay put :)


Note: It will probably help to know that i'm using the Apron tutorials camera setup
That's what glOrtho is for. Here's some sample code (in Java):

GL11.glDisable(GL11.GL_DEPTH_TEST);GL11.glDisable(GL11.GL_LIGHTING);GL11.glMatrixMode(GL11.GL_PROJECTION);GL11.glPushMatrix();GL11.glLoadIdentity();GL11.glOrtho(0,width,32,height,-1,1);GL11.glMatrixMode(GL11.GL_MODELVIEW);GL11.glPushMatrix();GL11.glLoadIdentity();// draw all your text hereglPrint(width - 100, height - 20, "FPS: " + (int)time.getFrameRate() );GL11.glMatrixMode(GL11.GL_PROJECTION);GL11.glPopMatrix();GL11.glMatrixMode(GL11.GL_MODELVIEW);GL11.glPopMatrix();GL11.glEnable(GL11.GL_DEPTH_TEST);GL11.glEnable(GL11.GL_LIGHTING);
Well - i'm programming with c++
Quote:Original post by Beaverbutt8
Well - i'm programming with c++


The code is all the same, it's just OpenGL calls. Remove "GL11." and replace the glPrint with your own, and you're basically good to go. Don't be lazy now ^_^
ok,

now i can't see the text or 3d world


___
0_o
~
I'm assuming you're using outline fonts here, so if you're not, please excuse me.

Now, you want to keep the Z axis for the outline font stationary. Outline fonts will always have a Z axis that can rotate, so instead of using them you'd be so much better off using bitmap fonts which are 2D. Use some of the code from this tutorial.

Good luck!
I am using 2d fonts based on NeHe's lesson 13
If you're using bitmapped fonts and you're rnedering them at the correct place you shouldn't have a problem with rotation.
Maybe this code can help you.

// render 3d scene...// switch the projectionsglMatrixMode(GL_PROJECTION);// clear the current projectionglLoadIdentity();// create an ortho matrix bound to the size of the windowglOrtho(0.0, nWndWidth,        0.0, nWndHeight,        -1.0, 1.0);// switch back to the modelview matrixglMatrixMode(GL_MODELVIEW);// enable / disable statesglEnable(GL_TEXTURE_2D);glDisable(GL_DEPTH_TEST);// push a model view matrixglPushMatrix();// load the identity matrix// this step can be skipped if the model view matrix// is going to be the identity matrixglLoadIdentity();// draw the text between: [0.0, nWndWidth]  ---> X//                        [0.0, nWndHeight] ---> Y//                        [0.0]             ---> ZglBindTexture(GL_TEXTURE_2D, nTexUnit);// begin drawing quadsglBegin(GL_QUADS);glTexCoord2f(0.0f, 0.0f); glVertex3f(1.0f,  1.0f,  0.0f);glTexCoord2f(1.0f, 0.0f); glVertex3f(11.0f, 1.0f,  0.0f);glTexCoord2f(1.0f, 1.0f); glVertex3f(11.0f, 11.0f, 0.0f);glTexCoord2f(0.0f, 1.0f); glVertex3f(1.0f,  11.0f, 0.0f);// stop drawing quadsglEnd();// pop a model view matrixglPopMatrix();// enable / disable statesglEnable(GL_DEPTH_TEST);glDisable(GL_TEXTURE_2D);


Assuming I haven't messed the code up, this should get you want you want. I haven't looked at the Nehe tutorials, but I prerender all the text before it is displayed. I'm sure it is along the same lines as this.

This topic is closed to new replies.

Advertisement