Jump to content
  • Advertisement
Sign in to follow this  
brandonman

Fonts

This topic is 3985 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone. I just finished up a pong game and It is actually pretty fun, yay! But I'm using cout right now to show the score. I need to a way to do fonts, and the nehe lesson 13 does not seem to support variables.I have 2 variables, playerscore and aiscore. How do I print these? Please link me to a tutorial or some code please. I could do an if(aiscore==1) *call the glPrint for 1*, but that'd be kind of cheating and not a very good coding habit.

Share this post


Link to post
Share on other sites
Advertisement
From using cout I assume you use C++ so you could use sprintf(...) instead.

For rendering try bitmap fonts or texture mapped fonts (with freetype for example).

Share this post


Link to post
Share on other sites
Quote:
Original post by Lord_Evil
From using cout I assume you use C++ so you could use sprintf(...) instead.


Or he could actually *use* C++ and use the std::stringstream class instead. Since it's interface is surprisingly like (cough cough) std::cout's, it would be very familiar and easy-to-use for him. Google it!

Share this post


Link to post
Share on other sites
sprintf is bad, just use stringstreams as Ezbez suggests. String streams work very much like cout and cin. From there you can pass the string to your print function. If you need a "char *" or "const char *" then use the ".c_str()" function of the string class.

Share this post


Link to post
Share on other sites
Quote:

Original post by Ezbez
Or he could actually *use* C++ and use the std::stringstream class instead. Since it's interface is surprisingly like (cough cough) std::cout's, it would be very familiar and easy-to-use for him.


You're right. I knew there was a better way to deal with strings using the STL but I didn't remember it anymore.

Quote:

Original post by brandonman
Aren't these for C++? Do they actually print to an opengl window?


No, the C++ functions like sprintf(...) or classes like std::stringstream don't render text to an OpenGL window. They just produce formatted strings.

For rendering you take those strings and render them by using a bitmap or texture mapped font. Bitmap font basically draw part of a texture per character on the screen whereas texture mapped fonts apply that texture region to geometry (usually a quad).

So you have a texture where all the characters you need are drawn to. You also have a list with information which part of the texture corresponds to a character as well as other usefull information such as character width. With texture mapped fonts you then read each single character of the string and draw a quad for that character using the appropriate texure and texture coordinates.

[google] for more information on bitmap fonts or texture mapped fonts.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!