Hi, my teacher,
I can show texts of char type using
glListBase(1000);
glCallLists(Twidth,GL_UNSIGNED_BYTE,Text[i]);
But how to show float number in OpenGL?
thanks!
Hi, my teacher,
I can show texts of char type using
glListBase(1000);
glCallLists(Twidth,GL_UNSIGNED_BYTE,Text[i]);
But how to show float number in OpenGL?
thanks!
You use the same technic, but you convert the float number to a string. Use your favorite library or your own code to do that.
NAOQ - not a advanced opengl question
V-man
------------------------------
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
[QUOTE]Originally posted by V-man:
[B]You use the same technic, but you convert the float number to a string. Use your favorite library or your own code to do that.
I have convert it to a string. But how to show decimal's position. I want to know whether to show float number directly,which needn't convert or use own code.
sprintf
NEVER use sprintf with floating point numbers. Always a risk of a crash. Use snprintf instead to guard your buffer sizes.
!!!!! (speaking from experience of course).
As you can use %5.5 you can avoid the crash.
- Michael Steinberg
I agree with mike, you simply have to make sure your buffer can accomidate the number of digits you are going to generate. In reality this isn't a big deal. Just make your buffer a resonable size and its an issue that should never come up. I really don't think that this borders on the line of a buffer overrun type of hack.Originally posted by Michael Steinberg:
As you can use %5.5 you can avoid the crash.
(:
Devulon
5.5 won't limit you to 5 output characters.
It simply means miniumum of 5 characters, with a precision of 5 decimal places.
Knackered
... to avoid buffer overruns.Code :#include <sstream> using namespace std; ... { ostringstream s; s << myFloat; // the number as a string is now available in s.str() }
Paranoia! Will destroy ya!
(By the way, printf and sprintf are so incredible to use compared to C++ formatting statements. You want to talk about one major step backwards in the name of progress, this is it)