lesson 17 question
Basically, I have a variable (usually a float) that I want to display on the screen. I''ve used lesson 17 to do this (slightly modified to use targas instead of bitmaps). But, it doesn''t quite work right. I was hoping that some people could help me out here. If you need anymore information, I wont hesitate to provide it.
Thanks,
Glenn Murphy
using glPrint....
ok. it takes in the position, and it also takes in a character pointer (char*) and a set variable. I''ll ignore all but the char* since this is obviously the important one
ok..
Now, I''ll assume your using the stl string container for your string manipulation (if your not you should be )
to set a string to the value of a float, you would generally do this:
You could simply have it return a char* but I discourage this in favour of returning a string, since the char* returned would always be the same, and you could easily run into problems where you call the function twice and expect two different char*''s (if you get me).
to int:
find out more here
then it would just be a matter of doing:
| - My project website - | - email me - |
ok. it takes in the position, and it also takes in a character pointer (char*) and a set variable. I''ll ignore all but the char* since this is obviously the important one
ok..
Now, I''ll assume your using the stl string container for your string manipulation (if your not you should be )
#include <string>using std::string;
to set a string to the value of a float, you would generally do this:
string floatToString(float value){ char buffer[64]; _gcvt(double(value),10,buffer); string str; str.assign(buffer); return str;}
You could simply have it return a char* but I discourage this in favour of returning a string, since the char* returned would always be the same, and you could easily run into problems where you call the function twice and expect two different char*''s (if you get me).
to int:
string intToString(int value){ char buffer[64]; _itoa(value,buffer,10); string str; str.assign(buffer); return str;}
find out more here
then it would just be a matter of doing:
...string value= floatToString(5.3521f);string message = "the value of the number is: ";glPrint(x,y,message + value, set);...
| - My project website - | - email me - |
You could also use the va_arg system instead.
You have to remember that you''re unique, just like everybody else.
You have to remember that you''re unique, just like everybody else.
But, glCallLists needs a pointer (I'm terrible with pointers, I'm working at getting better though). How would I use your example while using pointers?
Also, if you have a good resource for pointers, that'd help, too.
Thanks again,
Glenn Murphy
EDIT (13:33 CST): scratch that. I just looked it up on google and a lot of my books lying around and found my answer (I feel quite stupid sometimes at how the answer is right in front of me (especially when I find it a couple hours after asking other people)). But, I do have another question, if ya'll don't mind. When using glCallLists, the second arguement ("type: The type of values in lists. The following symbolic constants are accepted: ...") what size would I use when using a string? Thanks again for my help and for (atleast) acting patient with me...
[edited by - gyrmnix on April 23, 2004 2:54:57 PM]
Also, if you have a good resource for pointers, that'd help, too.
Thanks again,
Glenn Murphy
EDIT (13:33 CST): scratch that. I just looked it up on google and a lot of my books lying around and found my answer (I feel quite stupid sometimes at how the answer is right in front of me (especially when I find it a couple hours after asking other people)). But, I do have another question, if ya'll don't mind. When using glCallLists, the second arguement ("type: The type of values in lists. The following symbolic constants are accepted: ...") what size would I use when using a string? Thanks again for my help and for (atleast) acting patient with me...
[edited by - gyrmnix on April 23, 2004 2:54:57 PM]
if your passing in a pointer to a block of memory for characters (char*), where each char in that block of memory is a signed byte, then use GL_BYTE, since GL_BYTE is -128 to 127.. which is exactly the same range of a signed byte.
I''d suggest you look through all the C/C++ tutorials on game tutorials a few times. They will help you understand whats happening with pointers, and other concepts that your bound to stumble apon sooner or later.
They are good, so I suggest you do this.
| - My project website - | - email me - |
I''d suggest you look through all the C/C++ tutorials on game tutorials a few times. They will help you understand whats happening with pointers, and other concepts that your bound to stumble apon sooner or later.
They are good, so I suggest you do this.
| - My project website - | - email me - |
A simple templated conversion function...
You should never let your fears become the boundaries of your dreams.
template <class Type>inline std::string ValueToString( const Type value ) { std::stringstream str; str << value; std::string res; str >> res; return res;}
You should never let your fears become the boundaries of your dreams.
I am currently reading through the tutorials on gametutorials.com (thanks for the link). But, one more quick question, my glCallLists looks like:
glCallLists(sizeof(str), GL_BYTE, &str);
It works fine except, it adds ''cB'' at the end of the phrase and I can''t figure out why. What would cause this to happen. Thanks for all the help.
Glenn Murphy
glCallLists(sizeof(str), GL_BYTE, &str);
It works fine except, it adds ''cB'' at the end of the phrase and I can''t figure out why. What would cause this to happen. Thanks for all the help.
Glenn Murphy
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement