Text With OpenGL

Started by
0 comments, last by Fahrenheit451 18 years, 10 months ago
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?
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

This topic is closed to new replies.

Advertisement