Public Group

# Rendering text in a 3d enviroment

This topic is 4503 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I've written a program with some 3d bits and bobs, and want to have text on the screen. 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()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer
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
glDisable(GL_LIGHTING);
// Pulsing Colors Based On Text Position
glColor3f(1.0f*float(cos(cnt1)),1.0f*float(sin(cnt2)),1.0f-0.5f*float(cos(cnt1+cnt2)));
// Position The Text On The Screen
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_LIGHTING);
glMatrixMode(GL_MODELVIEW);

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

glFlush();

}


##### Share on other sites
are your certain that before DrawScene() is called, the modelview matrix is the current matrix? because if it wasn't, that would cause the models to be hidden but the text to be displayed. to be safe i would always:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth BufferglLoadMatrix(GL_MODELVIEW); // just to be safeglLoadIdentity();

also, those NeHe tutorials really need to be updated. they aren't as clean as i'd like them to be, and are kinda outdated. i mean, WindowPos has made RasterPos obsolete in this case, as i can't even remember the last time i used RasterPos ha ha ha.

also, i see you disabled lighting but not texture2D, but if ur text displays right then i guess that isn't a problem.

also, the way you define your vector camera is very fishy, setting pitch and yaw, and then setting the up vector to the y-axis... gluLookAt is going to modify that up vector, and perhaps give you results you might not be expecting. i think this is why you probably aren't seeing your terrain model; in that something is really awry with your vector camera.

also curious as to why you did this before u drew the text as it isn't necessary...

glLoadIdentity();							// Reset The Current Modelview MatrixglMatrixMode(GL_PROJECTION);				// Go to projection mode

##### Share on other sites
Quote:
 Original post by yadangoalso curious as to why you did this before u drew the text as it isn't necessary...glLoadIdentity(); // Reset The Current Modelview MatrixglMatrixMode(GL_PROJECTION); // Go to projection mode

well what i did was a mild mishmash of a google of "display text in opengl" and the tutorial...flat out copying it and putting it in did nothing so i searched to see if there was a specific implimentation, what i found suggested putting those lines in beforehand. without them i get squat.

also for some reason glLoadMatrix(GL_MODELVIEW); gives me an "undeclared identifier" error. its fine with glLoadMatrixf (although wont accept GL_MODELVIEW) as a parameter.

1. 1
2. 2
3. 3
4. 4
frob
15
5. 5

• 16
• 12
• 20
• 12
• 18
• ### Forum Statistics

• Total Topics
632161
• Total Posts
3004505

×