• Advertisement
Sign in to follow this  

displaying numbers using opengl

This topic is 1839 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

Advertisement
http://jonmacey.blogspot.com/2011/10/text-rendering-using-opengl-32.html

Found this within 3 seconds of googling.

Share this post


Link to post
Share on other sites
I'd suggest buying yourself a copy of C# Game Programming for Serious Game Creation. I see that you're using C++, but that book answers a lot of your questions (looking at your post history), including this one, and I think translating the code from C# (a very easy-to-read language) to C++ might be good practice for you. Alternatively you might find you like C#'s syntax to be more your speed, in which case, great. Edited by NoAdmiral

Share this post


Link to post
Share on other sites
if you are using freeglut you can use the functions glutBitmapString or glutStrokeString
otherwise you will have to create them from scratch:
1. make/search an image with all the numbers you want to display (e.g. search for ascii texture)
2. write/find some code to load images
3. create a texture from it
4. draw some quads with the right texture coordinates to select the correct character from your texture

Share this post


Link to post
Share on other sites
well I figured out how to print strings to the screen, now I want to print numbers to the screen for scoring purposes.
here is the code I am using.

GLuint fontOffset;
void makeRasterFont(void)
{
GLuint i;
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
fontOffset = glGenLists (128);
for (i = 32; i < 127; i++) {
glNewList(i+fontOffset, GL_COMPILE);
glBitmap(8, 13, 0.0, 2.0, 10.0, 0.0, rasters[i-32]);
glEndList();
}
}

void myinit(void)
{
glShadeModel (GL_FLAT);
makeRasterFont();
}

//print the string
void printString(char *s)
{
glPushAttrib (GL_LIST_BIT);
glListBase(fontOffset);
glCallLists(strlen(s), GL_UNSIGNED_BYTE, (GLubyte *) s);
glPopAttrib ();
}

Share this post


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

  • Advertisement