Displaying counters

Status
Not open for further replies.

Eragon0605

Wise, Aged Ars Veteran
198
Hello, all. I was wondering how counters (like a score counter or an HP/MP counter) can be made as strings or chars so they can be displayed as text in a window. Or if there is a font library that displays integers. My Stuff:
Programming Language: C++
Graphics API: OpenGL
Other API's: SOIL, GLUT, and fnt from the plib library
OS: Kubuntu 10.04
 

Jonathon

Ars Legatus Legionis
17,646
Subscriptor
Pure C++ way:

Code:
int count;

//do stuff to set count here

ostringstream counterStream; //this is an ostream; you can use it just like cout or an ofstream
counterStream << "Count: " << count;

string counterString = counterStream.str();

Then render counterString in the same way you would render any other string.

There are about half a dozen different ways to do this; one of the libraries you're using (if you're using KDE's libs, for example) may have something a bit cleaner. You could also go the straight C route and use snprintf; this might be a bit more appropriate if your rendering method takes a C string (char *) rather than a C++ string.
 
Status
Not open for further replies.