Skip to main content
GameDev.net gamedev.net
🔒 Locked

Stupid question

Started by Marty666 Jan 9, 2004 at 5:19 AM 4 replies 450+ views
Original Post
Marty666
Marty666
Hi all, I started programming again. I''m trying to make a simple 3D game using glut. I use the glutBitmapCharacter function to put text on screen. This works, but the text seems to stay in one place when i move the camera, while i want it to stay in the same place on the screen. I use glRasterPos to prevent this, but the text is now invisible. I tried pushing the matrix then setting it to projection then using gluOrtho2D before drawing the text and then setting the matrix back to modelview and popping the matrix, but this seems to have strange effects. (All is rendered on bottom row of pixels only, rest is black) How can i switch between 2D and 3D easilly and fast to write fonts to the screen and render 3D? Thanx, Marty
_ /__ /|| | || MtY | ||_____|/Marty
Tree Penguin
Tree Penguin
This:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)scrw/(GLfloat)scrh, 0.1f, 500.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Draw 3D

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0,scrw,scrh,0.0,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Draw 2D


This works fine for me, if it''s fast, i don''t know, it is fast enough not noticing horrible fps decreasing.
Marty666
Marty666

void Print(float x, float y, char *string)
{
glMatrixMode(GL_PROJECTION); //This is the matrix to set before gluOrtho2D, right?
glPushMatrix(); //Keep the matrix before I glLoadIdentity
glLoadIdentity(); //Reset it
gluOrtho2D(800, 0, 600, 0); //Make the Ortho Raster
glDisable(GL_DEPTH_TEST); //Do I need this?

int length;
length = strlen(string); //This many chars to draw
glRasterPos2i(x,y); //Start at this RasterPos
for (int i = 0; i < length; i++)
glutBitmapCharacter(GLUT_BITMAP_9_BY_15, string); //Do ''m all

glEnable(GL_DEPTH_TEST); //Do I need this?
glPopMatrix(); //Restore my old matrix
glMatrixMode(GL_MODELVIEW); //Go on in 3D
}
_ /__ /|| | || MtY | ||_____|/Marty
Marty666
Marty666
This should work, right?
So why don''t i see any fonts on screen?

Thanx, Marty
_ /__ /|| | || MtY | ||_____|/Marty
Tree Penguin
Tree Penguin
Try translating one unit away, the character might be at the same depth as the camera''s origin (0).
Marty666
Marty666
Ok, it works, thanx for helping!

For anyone that''s looking for glut fonts:


void Print(float x, float y, char *string)
{
glMatrixMode(GL_PROJECTION);
glPushMatrix(); // save projection matrix
glLoadIdentity(); // reset projection matrix
glOrtho(0.0,800,600,0.0,-1.0,1.0); //set up 2D
glMatrixMode(GL_MODELVIEW);
glPushMatrix(); // save modelview matrix
glLoadIdentity(); // reset modelview matrix
int length;
length = strlen(string); // This many chars to draw
glRasterPos2i(x,y); // Start at this RasterPos
for (int i = 0; i < length; i++)
glutBitmapCharacter(GLUT_BITMAP_9_BY_15, string); //Do ''m all
glMatrixMode(GL_PROJECTION);
glPopMatrix(); // Restore projection matrix
glMatrixMode(GL_MODELVIEW);
glPopMatrix(); // Restore modelview matrix
}
_ /__ /|| | || MtY | ||_____|/Marty

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.