Advertisement Jump to content
Sign in to follow this  
WilyCoder

OpenGL Text With OpenGL

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

I'm stumped! First I make a font:
HFONT	oldfont;

Win32Object.Base = glGenLists(96);					
Win32Object.Font = CreateFont(	-24,		
					0,	
					0,	// Angle Of Escapement
					0,
					FW_BOLD,	
					FALSE,		// Italic
			FALSE,				// Underline
			FALSE,				// Strikeout
			ANSI_CHARSET,	
			OUT_TT_PRECIS,	
			CLIP_DEFAULT_PRECIS,
			ANTIALIASED_QUALITY,
			FF_DONTCARE|DEFAULT_PITCH,	
			"Courier New");	
oldfont = (HFONT)SelectObject(Win32Object.Hdc, Win32Object.Font);		
wglUseFontBitmaps(Win32Object.Hdc, 32, 96, Win32Object.Base );			
SelectObject(Win32Object.Hdc, oldfont);
DeleteObject(Win32Object.Font);	

Then I render it:
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
gluOrtho2D(0,400, 400, 0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glColor3f(1.0f,1.0f,1.0f);
	
//glTranslatef(0.0f,0.0f,-3.0f);
	
glRasterPos3f(0,3,-10);
glPushAttrib(GL_LIST_BIT);			
glListBase(Win32Object.Base - 32);		
glCallLists(strlen("OpenGL Text"),GL_UNSIGNED_BYTE,"OpenGL Text");
glPopAttrib();
SwapBuffers(Win32Object.Hdc);	

I can't for the life of me figure out why I do not see text. Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
My print routine goes something like this for OpenGL text:


glColor4f(r, g, b, a);
glPushMatrix();
if (display2D==true) {
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -1.0f); // translate one unit into the screen
glRasterPos2i(screenX, screenY);
} else {
glRasterPos3f(xpos,ypos,zpos);
}
glPushAttrib(GL_LIST_BIT);
glListBase(callList - 32);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
glPopAttrib();
glPopMatrix();



Looks like you have most of it down. You definitely need to translate out slightly to see the text in orthographic mode.

hth
F451

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!