Archived

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

Font and Display-list troubles

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

Hi. I have a problem with my font writting code. To start, I'll dump the code:
    
void CFont::Write(float scale_factor, char *fmt, ...)
{
	if(fmt == NULL)
		return;

	glPushMatrix();					//Push the current matrix

	glPushAttrib(GL_LIST_BIT);

	glScalef(scale_factor, scale_factor, 1);			//Scale to users factor


	va_list		ap1;					// Pointer To List Of Arguments

	char text[256];

	va_start(ap1, fmt);					// Parses The String For Variables

	    vsprintf(text, fmt, ap1);				// And Converts Symbols To Actual Numbers

	va_end(ap1);						// Results Are Stored In Text


	glListBase(FntList);

	glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);	// Draws The Display List Text


	glPopAttrib();
	glPopMatrix();

	return;

}
    
The problem is that only the last letter in the string parsed to the function is diplayed. It looks like the calllists function is pilling all the letters on top of each other, but why? I read in the NeHe tut's that it moves them along the width of the size of the quad. It has nothing to do with the scalef function, i tried removing it. The font was generated from a bmp file and made into 256 quads. I know there is nothing wrong with that code, it works fine. If there are any ideas on this, it will be very helpful. Thanks, -J [edited by - jason2jason on June 23, 2002 1:50:03 PM]

Share this post


Link to post
Share on other sites

    
void CFont::BuildFont(CTexture* fnt = &FT_ARIAL)
{
FntList = glGenLists(256); //Generate blank lists for font


float a,b; //Temp vars for working out tex coords

const float n = 0.0625; //Width of font in bmp

int i = 0;

for(float u = 0.0; u < 16.0; u += 1.0) //Loop to create all font lists

{
for(float v = 0.0; v < 16.0; v += 1.0)
{
a = u*n;
b = v*n;


//a= 1;

//b= 0;


glNewList(FntList+i, GL_COMPILE); //New list offset by the fntbase


fnt->USE(); //Set to texture font


glBegin(GL_QUADS); //Create a 1x1 unit quad

glTexCoord2f(b,-a);
glNormal3f(0.0,0.0,1.0);
glVertex3f(-0.5, 0.5,0.0);

glTexCoord2f(b+n,-a);
glNormal3f(0.0,0.0,1.0);
glVertex3f( 0.5, 0.5,0.0);

glTexCoord2f(b+n,-a-n);
glNormal3f(0.0,0.0,1.0);
glVertex3f( 0.5,-0.5,0.0);

glTexCoord2f(b,-a-n);
glNormal3f(0.0,0.0,1.0);
glVertex3f(-0.5,-0.5,0.0);
glEnd();

glEndList();

//CheckGLErrors("Dislist end",glGetError(),NULL);

i++;
}
}
}


I got the tex coords right over trail and error today, but I can't see anything wrong, and there are no open GL errors. The commented a= 1; b= 0; were just for testing.

-J

[edited by - jason2jason on June 23, 2002 3:46:22 PM]

Share this post


Link to post
Share on other sites
lesson17.cpp has this little bit after glEnd call:

glTranslated(10,0,0); // Move To The Right Of The Character

That's in BuildFont function.

You have to manually advance your position after each character. You should use real character width instead of '10', as hardcoded in lesson 17. Also, I think vertex arrays are way better than display lists for fonts, so if you want to have a faster font engine, I suggest you use vertex arrays.

[edited by - IndirectX on June 23, 2002 4:01:43 PM]

Share this post


Link to post
Share on other sites
Does that mean I cant use the glCallLists() function? The first time i tried using glCallList in a for loop and translating, but it didn''t work, i''ll have another go at it tho. Is that what you ment? Also do you know where there are any good vertex array tutorials?

thx,

-J

Share this post


Link to post
Share on other sites
quote:
Original post by Jason2Jason
Does that mean I cant use the glCallLists() function?


Well, you can. When you''re building display list for each letter, add glTranslate(letter_width, 0, 0) after you call glEnd and before you call glEndList. This way when next list is called, horizontal position will be updated.
quote:

Also do you know where there are any good vertex array tutorials?


A quick search on Google revealed this, for example.

My vertex array GL font class was actually a port of CD3DFont from DirectX SDK samples, in case you''re wondering.

Share this post


Link to post
Share on other sites