PDA

View Full Version : writing numbers on the screen



glguru
02-24-2000, 06:28 PM
Hi,
I want to display a set of 3D (float) coordinates on the screen. I know you can use glRasterPos and glutBitmapCharacter to display a character but I am lost on writing float values. Any help is appreciated.

nickels
02-24-2000, 06:38 PM
I don't know, but if you can display any character, can you do something like this:

float x;
char *ptr;
char buf[1024];
x = 3.14 (etc...)
sprintf(buf, "%f", x);
for(ptr = &buf[0]; ptr; ptr++)
{
display_gl_char(*ptr);
}

mike j
02-24-2000, 06:47 PM
use sprintf()
this is what I got to work...

char str[] //storage for string

sprintf(str, "myfloat: %f", outputVar);

glRasterPos2f(-50, -50);
len = (int)strlen(str);
for (i=0; i<len; i++)
{
glutBitmapCharacter(hudFont, str[i]);
}




[This message has been edited by mike j (edited 02-24-2000).]

nickels
02-24-2000, 06:59 PM
Wait a minute. That line has to be:

for(ptr = &buf[0]; *ptr; ptr++)

(Test for null at end of string)

glguru
02-25-2000, 07:08 AM
Thanks alot mikej and nickels.


glguru