Archived

This topic is now archived and is closed to further replies.

bitmap font issues

This topic is 5318 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 trying to use windows fonts BUT when i put my string in my function for outputting text, there are no spaces, and the very bottom of each character is being 'cut off' some how. So when i try and print the text "Hello World!", i get "HelloWorld!" w/ the bottom cut off, i've also tried "Hello\ World!" and that doesn't make a difference. here's my code:
//font.h

unsigned int base = glGenLists(96);
int fontStatus = false;

int loadFont(char *fontName, int size)
{
	fontStatus = false;
	HFONT hFont;	//windows font

	//create a 14ptCourier Font
	hFont = CreateFont(size, 0, 0, 0, FW_HEAVY, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE | DEFAULT_PITCH, fontName);

	// did the font get created?
	if(!hFont)
		return fontStatus;
	else
		fontStatus = true;

	//device context
	SelectObject(g_HDC, hFont);

	//prepare bitmap font
	wglUseFontBitmaps(g_HDC, 32, 96, base);

	return fontStatus;
}

int printText(char *str)
{
	if((!fontStatus) || (str == NULL))
		return false;

	glPushAttrib(GL_LIST_BIT);
		glListBase(base - 32);
		glCallLists(strlen(str), GL_UNSIGNED_BYTE, str);
	glPopAttrib();

	return true;
}

void clearFont()
{
	if(base)
		glDeleteLists(base, 96);
}
 
and here's where i use it:
void drawScene()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	glTranslatef(0.0f, 0.0f, -1.0f);
	glColor3f(0.0f, 0.8f, 0.2f);
	glRasterPos2f(-.35f, 0.0f);
	printText("OpenGL Bitmap Fonts!");
	
	glFlush();	
	SwapBuffers(g_HDC);
}
[edited by - stond on May 27, 2003 9:05:53 PM]

Share this post


Link to post
Share on other sites