displaying numbers using opengl

Started by
7 comments, last by phil67rpg 11 years, 3 months ago
I want to display a score number for my breakout game but I am unsure of how to begin.
Advertisement
http://jonmacey.blogspot.com/2011/10/text-rendering-using-opengl-32.html

Found this within 3 seconds of googling.

Software Engineer | Credited Titles: League of Legends, Hearthstone

I don't want to use shaders yet.
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.

Inspiration from my tea:

"Never wish life were easier. Wish that you were better" -Jim Rohn

soundcloud.com/herwrathmustbedragons

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
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 ();
}

well I googled this topic but did not find very much, there has to be a simple way to print numbers to the screen.
Since you have the ability to draw strings to the screen, you should look into how to convert integers into strings in your language of choice.
I am using c++ and opengl

This topic is closed to new replies.

Advertisement