View Full Version : displaying text on opengl
04-13-2005, 03:54 AM
How do you display simple 2d text on an opengl screen, i want to display the score of a simple game program but dont know how to show the score up on screen in an opengl environment. can someone please help???
Well, the simplest way would be to use glut if you're familiar with it (though I don't know for sure if yo can use its functions if you haven't created a window using glut, but chances are you can). On the other hand there are a few libraries out there that handle the font loading for you. I'm sorry but I can't remember any names.
As a last resort you could use the operating system's fonts along with wgl (or xgl) functions to create the glyphs. I don't think it's as hard as it sounds. Good luck!
04-14-2005, 12:01 AM
You can build font (windows function CreateFont)
like that :
</font><blockquote><font size="1" face="Verdana, Arial">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">unsigned int CreateBitmapFont(char *fontName, int fontSize)
unsigned int base;
g_HDC = GetDC(g_HDC);
base = glGenLists(96);
hFont = CreateFont(fontSize, 0, 0, 0, 600, FALSE, FALSE, FALSE, ANSI_CHARSET,
OUT_STRING_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,FF_DONTCARE | DEFAULT_PITCH, fontName);
wglUseFontBitmaps(g_HDC, 32, 96, base);
and to print text:
void PrintString(unsigned int base, char *str)
if ((base == 0)
04-14-2005, 03:19 AM
thanks alot "DVM" and "saatric" u were spot on.
04-14-2005, 05:25 AM
There's also a number of tutorials at NeHe's site that deal with text in OpenGL.
http://nehe.gamedev.net Nehe OpenGL tutorials (http://nehe.gamedev.net)
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.