PDA

View Full Version : Urgent help needed. How can I use the glutBitmapCharacter to display ints? mdog1234?



BigShooter
10-23-2003, 12:07 PM
mdog1234, you some code for me, which will use glutBitmapCharacter to display char*. I'm trying (with no luck) to rewrite that function so that it will display integers (>9999, that is over 4 digits long).
How can I rewrite this function (below) to accept and display integers.
I'd really appreciate your help.
Thank you,
Luke

void Text: http://www.opengl.org/discussion_boards/ubb/tongue.gifrintText (void* font, char* string, int x, int y) {

if (string && strlen(string))
{
glPushMatrix();
glLoadIdentity();
glRasterPos2d(x,y);
while (*string)
{
glutBitmapCharacter(font,*string);
string++;
}
glPopMatrix();
}

}

nexusone
10-24-2003, 04:20 AM
You have to use a function like itoa to convert say a int to a ascii number or use sprintf.

Note itoa is not a standard C/C++ call (windows), for linux use the sprintf

int score;
char txt[32]; // space to put the converted data

itoa(score, txt, 10); // base 10 conversion

printText (...., txt, x, y);

or

sprintf( txt, "%6d", score ); // 6d = 000000 convert to six digits max

[This message has been edited by nexusone (edited 10-24-2003).]

[This message has been edited by nexusone (edited 10-24-2003).]

BigShooter
10-24-2003, 10:39 AM
OK, thank you for the help.