PDA

View Full Version : Problem rendering text with a 3d enviroment



Winegums
04-21-2006, 07:45 PM
Hi, I have a program with a 3d enviroment and wanted to put some 2d text up for debugging. I've tried implimenting the NeHe tutorial, but have came to a problem. If i render the text i see nothing but the text, and i dont know how to fix it. the problem seems to be changing the matrix mode to display the text, but changing back after drawing the text doesn't work.


void DrawScene()
{
char buffer[200];
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
// glLoadMatrix(GL_MODELVIEW); // just to be safe
glLoadIdentity(); // Reset The Current Modelview Matrix

float sy = sin(yaw);
float cy = cos(yaw);
float sp = sin(pitch);
float cp = cos(pitch);

WWLA[0] = WWA[0] + sy * cp;
WWLA[1] = WWA[1] - sp;
WWLA[2] = WWA[2] + cy * cp;

gluLookAt(
WWA[0], //Where we're at
WWA[1],
WWA[2],
WWLA[0], //Where we're looking at (based on where we're at)
WWLA[1],
WWLA[2],
0, //Which direction is up
1,
0
);

DrawModels();
glTranslatef(0.0f, 0.0f, 0.0f);
glCallList(terrainList);



glLoadIdentity(); // Reset The Current Modelview Matrix
glMatrixMode(GL_PROJECTION); // Go to projection mode
glPushMatrix(); // Remember where we're at
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
// Pulsing Colors Based On Text Position
// glColor3f(1.0f*float(cos(cnt1)),1.0f*float(sin(cnt 2)),1.0f-0.5f*float(cos(cnt1+cnt2)));
glColor4f(1.0f,0.0f,0.0f,1.0f);
// Position The Text On The Screen
sprintf(buffer, "blah blah blah");
glRasterPos2f(-0.45f+0.05f*float(cos(cnt1)), 0.32f*float(sin(cnt2)));
glPrint("Active OpenGL Text With NeHe - %7.2f", cnt1); // Print GL Text To The Screen
cnt1+=0.051f; // Increase The First Counter
cnt2+=0.005f; // Increase The First Counter
glEnable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING);
glMatrixMode(GL_MODELVIEW);
glPopMatrix();

SwapBuffers(ghdc);// Swap the frame buffers.


//CheckMouse(); //Check for mouse input
glFlush();

}with glMatrixMode(GL_MODELVIEW) commented out i get the text but no models, with it not commented out i get no text but models. am i doing something wrong?

memfr0b
04-22-2006, 02:19 AM
You're pushing the projection matrix, and later pop the modelview matrix. You have to call glPopMatrix before you change the matrix mode back to GL_MODELVIEW.

Winegums
04-22-2006, 03:02 AM
callng pop matrix first didn't work. i just get no text at all.

jide
04-22-2006, 04:23 AM
What's your projection matrix ?

Winegums
04-22-2006, 12:52 PM
um..even though that was a straightforward question i dont understand it. to be honest, im not even that sure about projection matrix. i 'think' it dictates camera orientation but im not even sure about that, and even if i take that to be true im still not sure how to tell you what my projection matrix is.

jide
04-22-2006, 01:00 PM
Using glOrtho for your projection matrix might help.


glMatrixMode (GL_PROJECTION);
glOrtho (...);
glLoadIdentity();
// 2D texts here
glMatrixMode (GL_MODELVIEW);
// back to modelisation visualisation

Winegums
04-24-2006, 10:57 PM
i tried using ortho, but it doesn't work. appears to clear to a black screen

glMatrixMode (GL_PROJECTION);
glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0);
glLoadIdentity();
// 2D texts here
glRasterPos2f(-0.45f+0.05f*float(cos(cnt1)), 0.32f*float(sin(cnt2)));
glPrint("Active OpenGL Text With NeHe - %7.2f", cnt1); // Print GL Text To The Screen

glMatrixMode (GL_MODELVIEW);

zeoverlord
04-25-2006, 02:53 AM
Linky (http://www.gamedev.net/community/forums/topic.asp?topic_id=388298)
Have no time to type.