Jump to content
  • Advertisement
Sign in to follow this  

OpenGL 3D Text

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

Hello all, I have a quick question. Do I have to use the Microshaft framework in order to render 3D text? I tried using wgl as per the OpenGL Superbible and my text won't appear. Here are the functions I use to create a font and print to the screen

HDC	hDC=NULL;		//Private GDI Device Context
GLuint	base;	             //Base Display List For The Font Set
GLYPHMETRICSFLOAT gmf[256]; //Storage For Information About Our Outline Font Characters

GLvoid BuildFont(GLvoid)							
	HFONT	font;										//Windows Font ID

	base = glGenLists(256);								//Storage For 256 Characters

	font = CreateFont(-12,      						//Height Of Font
						0,								//Width Of Font
						0,								//Angle Of Escapement
						0,								//Orientation Angle
						FW_BOLD,						//Font Weight
						FALSE,							//Italic
						FALSE,							//Underline
						FALSE,							//Strikeout
						ANSI_CHARSET,					//Character Set Identifier
						OUT_TT_PRECIS,					//Output Precision
						CLIP_DEFAULT_PRECIS,			//Clipping Precision
						ANTIALIASED_QUALITY,			//Output Quality
						FF_DONTCARE|DEFAULT_PITCH,		//Family And Pitch
						"Comic Sans MS");				//Font Name

	SelectObject(hDC, font);							//Selects The Font We Created

	wglUseFontOutlines(	hDC,							//Select The Current DC
						0,								//Starting Character
						255,							//Number Of Display Lists To Build
						base,							//Starting Display Lists
						0.0f,							//Deviation From The True Outlines
						0.2f,							//Font Thickness In The Z Direction
						WGL_FONT_POLYGONS,				//Use Polygons, Not Lines
						gmf);							//Address Of Buffer To Recieve Data

GLvoid glPrint(const char *fmt, ...)					
	float		length=0;								//Used To Find The Length Of The Text
	char		text[256];								//Holds Our String
	va_list		ap;										//Pointer To List Of Arguments

	if (fmt == NULL)									//If There's No Text
		return;											//Do Nothing

	va_start(ap, fmt);								    vsprintf(text, fmt, ap);						

	for (unsigned int loop=0;loop<(strlen(text));loop++)	//Loop To Find Text Length
		length+=gmf[text[loop]].gmfCellIncX;			//Increase Length By Each Characters Width

	glTranslatef(-length/2,0.0f,0.0f);					//Center Our Text On The Screen
	glPushAttrib(GL_LIST_BIT);							//Pushes The Display List Bits
	glListBase(base);									//Sets The Base Character to 0
	glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);	//Draws The Display List Text
	glPopAttrib();										//Pops The Display List Bits

In my RenderScene(), I use this:
	      glTranslatef(60.0f, 50.0f, 0.0f);
		glColor3ub(0, 255, 0);

So, can someone please let me know whether or not I have to use Microshaft's window foundation? Thanks in advance

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!