Lesson: 17
I am having some issues with implimenting Lesson 17...
This was the only way that I could get font to show up in my program. Every other way came out as a mess.
Ok so I have it working but i am only able to print out Char * Formated strings
Now.. I need to beable to print out dynamic integers (floats would be nice too but not nessisary). Every function that I have tried (itoa, sprintf, etc) has either output the wrong format, or made some very strange results.
I thought sprintf was going to be my saviour. I found a simple function and tried to impliment it. This is the function and how i tried to use it.
char* i2Str(int aV)
{
char buf[128];
sprintf(buf, "%d", aV);
return buf;
}
glPrint(50,50,i2Str(1234),1);
This should output:
1234
But it outputs:
, }
And the strange thing. The output dosnt change based on the argument I send to i2Str
The output changes when I change the size of the variable 'buf'
So unless theres somthing Im doing strange here, i dont know how to do this.
If anyone else uses this process to get text on the screen. how do you get your integer variables to output properly?
I don't know why it was not included, but you can use the method at the beginning of the function glPrint in lesson 14.
www.flashbang.se | www.thegeekstate.com | nehe.gamedev.net | glAux fix for lesson 6 | [twitter]thegeekstate[/twitter]
Your i2Str() function returns an address of a local buffer. This is a bad thing. The value in the buffer immediately get clobbered when you call glPrint(). One solution is to ditch the i2Str() function and just call sprintf() in the function that calls glPrint().
I noticed that your answer will always be something weird. This is because char buf[128] is defined in the scope of the function. When this function returns the buf variable is out of scope and so its memory is no longer in use. The method returns a pointer to the address of that local variable which ís no longer available after the method returns. It could well be used by another variable. Because of that you will get faulty results.
Hope that helps.
GBS
Hope that helps.
GBS
GBS
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement