Skip to main content
gamedev.net
🔒 Locked

Error creating font

Started by Lord Faron 1 reply 600+ views
Original Post
Lord Faron
Lord Faron
I'm trying to use wglUseFontBitmaps() to create font display list. The problem is wglUFB fails everytime. I don't know why. GetLastError() returns either 0 or 2. CreateFont() works fine - the font is created without any problems. I use NULL as the font name, but that's not the problem - I've tried several fonts. Everytime the font was succesfully created but wglUFB fails. My code is:

GFont *GOpenGLRenderer::CreateFont(LPCTSTR Name,int Size)
{
	GLYPHMETRICS gm;
	MAT2 m;

	guard(GOpenGLRenderer::CreateFont);
	gLog->Log("GOpenGLRenderer::CreateFont(): Creating font '%s'...\r\n",Name);
	wglMakeCurrent(Viewport->GetDC(),hRC);
	HFONT hFont = ::CreateFont(Size,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY,DEFAULT_PITCH | FF_DONTCARE,Name);
	if (!hFont)
	{
		gLog->Log("GOpenGLRenderer::CreateFont(): Failed (%u)!\r\n",GetLastError());
		return NULL;
	}
	HFONT Old = (HFONT)SelectObject(Viewport->GetDC(),hFont);
	GFont *Font = new GFont;
	if (Name) strcpy(Font->Name,Name);
	else strcpy(Font->Name,"Default");
	Font->Size = Size;
	Font->Bind = glGenLists(256);
	if (!wglUseFontBitmaps(Viewport->GetDC(),0,256,Font->Bind))
	{
		delete Font;
		SelectObject(Viewport->GetDC(),Old);
		DeleteObject(hFont);
		gLog->Log("GOpenGLRenderer::CreateFont(): Conversion failed (%u)!\r\n",GetLastError());
		return NULL;
	}
	m.eM11.value = 1; m.eM12.value = 0;
	m.eM21.value = 0; m.eM22.value = -1;
	m.eM11.fract = m.eM12.fract = m.eM21.fract = m.eM22.fract = 0;
	for (int i = 0; i < 256; i++)
	{
		GetGlyphOutline(Viewport->GetDC(),i,GGO_METRICS,&gm,0,NULL,&m);
		Font->Width = gm.gmCellIncX;
	}
	SelectObject(Viewport->GetDC(),Old);
	DeleteObject(hFont);
	return Font;
	unguard;
}

if (time() == $) { $ = 0; }
yadango
yadango
what does glGenLists return and at what point in your engine do you call GOpenGLRenderer::CreateFont?
Lord Faron
Lord Faron
glGenLists() returns 1. I call GOpenGLRenderer::CreateFont() after whole engine has been initialized (this includes OGL successful initialization).
if (time() == $) { $ = 0; }

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.