So far I have written a program that draws text to the screen and I am able to change the font type but I am unable to change the font size.

Here are the 3 main parts of my code that I think you need to see.

Font structure:

typedef struct Font
{
	const char* name;
	LONG height;
	GLuint base;
	GLYPHMETRICSFLOAT gmf[255];
};

Font creation and display functions:

void FONT::SetFont(const char* name, LONG height) //sets the font for the FontInstance
{
	HFONT hFont;
	LOGFONT logfont;
	logfont.lfHeight = -20; //this number does absolutely nothing
	logfont.lfWidth = 0;
	logfont.lfEscapement = 0;
	logfont.lfOrientation = 0;
	logfont.lfWeight = false;
	logfont.lfItalic = false;
	logfont.lfUnderline = false;
	logfont.lfStrikeOut = false;
	logfont.lfCharSet = ANSI_CHARSET;
	logfont.lfOutPrecision = OUT_DEFAULT_PRECIS;
	logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
	logfont.lfQuality = ANTIALIASED_QUALITY;
	logfont.lfPitchAndFamily = DEFAULT_PITCH;
	strcpy(logfont.lfFaceName, name);

	hFont = CreateFontIndirect( &logfont );


	SelectObject( hDC, hFont );

	font.name = name;
	font.height = height;
	font.base = glGenLists(255);

	wglUseFontOutlines(hDC, 0, 255, font.base, 0.0f, 0.1f, WGL_FONT_POLYGONS, font.gmf);

	DeleteObject( hFont );
}

void FONT::DrawFunc()
{
	glPushMatrix();
		glColor3fv(color);
		glPushMatrix();
			glTranslatef(0, 0, 0);

			glListBase(font.base);
			glCallLists( strlen(text), GL_UNSIGNED_BYTE, text );
		glPopMatrix();
	glPopMatrix();
}

For some reason no matter what value I give logfont.lfHeight the size of the text does not change. The only way that I have been able to modify the text size is through the use of glScalef(x,y,z) function but I really do not want to have to resort to that.

Also if this is a really poor way of printing text to the screen feel free to add what you think is a better way.

I have looked at doing raster drawing but since this is for drawing text on a user interface I would like to stick with the OpenGL unit system for drawing objects and text.

I can post up more code if needed.

Have a look at NeHe lesson 13, can easily change font with the variable there. It might be better, though more intensive, to create a number of font objects, each initialized with a different size, then find a way to toggle between them when needed. You could just call the font object in your DrawFunc.

Yeah I figured this out a while ago logfont.lfHeight does nothing so you have to use glScalef() to resize the fonts.

NeHe's tutorials are good for some things but for the most part I think that they are pretty out of date and I don't like using them unless I have to.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.