View Full Version : Displaying variables as text on screen

05-14-2005, 01:14 AM
how can i display my variables on the screen for real-time testing purposes? i can display strings on screen, but it only accepts "strings" and i always get these errors:

cannot convert parameter from 'float' to 'char *'

where i replace the strings with a different data type...

anyone have any ideas?

thank you =]

05-14-2005, 01:41 AM
Sounds like you're trying to cast a float into a string, you can't do that, you need (in most programming languages), to convert it yourself...


05-14-2005, 01:48 AM
how do i convert it?

05-14-2005, 02:03 AM
void PrintFloat(float value, int x, int y) {
char c[32];

sprintf(c, "%16.8f", value);
glRasterPos2i(x, y);
glCallLists(strlen(c), GL_UNSIGNED_BYTE, c); }
...assuming that you had a call to glXUseXFont() or something similar before.

05-14-2005, 11:05 AM
is that the best way to go about dispalying variables? is that how you woud do it? if not, how would you?

05-14-2005, 04:15 PM
Well, for C code sprintf is as good as they get. If you want to use pure C++ maybe you'd like to take a look at stringstreams (one word!)

05-15-2005, 02:03 PM
that is the best way for me to show variables on the screen. otherwise i would not have posted it :-)

but to be honest, the best way to watch over variables while running a prog is:

1. throw away your windows
2. install linux
3. now you can run a window-based prog, which may even use opengl, and you still can use >printf< to display whatever you want in a terminal.