Jump to content
  • Advertisement
Sign in to follow this  
McGrane

Question On Bitmap Font's, Opengl

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to master of fonts now :P (which only leaves particle systems for what i wanted to be able to do when i started :P ) But i am having trouble with it ... I have a rectangular box where the text should be displaying ... but its just that, its only a rectangle :P. Do i need to to add the Font File in the programs directory? - with that said i allready tried it without any succesion. Any idea's? Ill post the code if needed but i didnt see why it would be of need. I have pritty much pasted the code out of ' Opengl Game Programming ' Thanks ;)

Share this post


Link to post
Share on other sites
Advertisement
This will print your string in the upper right corner of the screen, should be trivial to get it to move around.

void stringDisplay(string stringIn)
{
glColor3f(1,.2,.2);
// Stolen from António Fernandes @ http://www.lighthouse3d.com/opengl/glut/
float x = 5, y = 30;

// switch to projection mode
glMatrixMode(GL_PROJECTION);
// save previous matrix which contains the
//settings for the perspective projection
glPushMatrix();
// reset matrix
glLoadIdentity();

// Get the Screen Properties
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT,viewport);

// set a 2D orthographic projection
gluOrtho2D(0, viewport[2], 0, viewport[3]);
// invert the y axis, down is positive
glScalef(1, -1, 1);
// mover the origin from the bottom left corner
// to the upper left corner
glTranslatef(0, -viewport[3], 0);
glMatrixMode(GL_MODELVIEW);

glPushMatrix();
glLoadIdentity();

//Render String
const char *c;
int x1 = (int)x;
for (c = stringIn.c_str(); *c != '\0'; c++) {
glRasterPos2f(x1, y);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *c);
x1 = x1 + glutBitmapWidth(GLUT_BITMAP_TIMES_ROMAN_24, *c) + 3;
}

//Reset Perspective
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);

}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!