Jump to content
  • Advertisement
Sign in to follow this  
Structural

Fonts not seamless

This topic is 5470 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 have a tad of a problem with fonts. They are not seamless. This shows up when underlining the font. A screenshot: The render code uses glCallLists as the list is generated when the font is loaded.
int Font::load()
{
	// the font definition is in the filename as provided:
	// <name>:<size>[:options].font

	HFONT oldFont;
	HFONT newFont;
	tagSIZE letterSize;
	HDC hDC;

	int size;
	char* sizepos;
	char* optpos;
	unsigned char letter;

	int opt_bold = FW_NORMAL;
	int opt_italic = FALSE;
	int opt_underline = FALSE;
	int opt_strike = FALSE;



	Data<HDC>* d = (Data<HDC>*)CDC::INSTANCE()->getData(DATA_TYPE_HDC);
	if (d)
	{
		hDC = d->get();
	}
	else
	{
		return -1;
	}

	if ((sizepos = strchr(fileName,':')) == NULL)
	{
		return -1;
	}

	if ((optpos = strchr(&sizepos[1],':')) != NULL)
	{
		*optpos = '\0';

		letter = optpos[1];
		while (letter != '.' && letter != '\0')
		{
			if (letter == 'b' || letter == 'B')
			{
				opt_bold = FW_BOLD;
			}
			if (letter == 'i' || letter == 'I')
			{
				opt_italic = TRUE;
			}
			if (letter == 'u' || letter == 'U')
			{
				opt_underline = TRUE;
			}
			if (letter == 's' || letter == 'S')
			{
				opt_strike = TRUE;
			}

			letter = optpos[1];
			optpos = &optpos[1];
		}
	}
	else if ((optpos = strchr(fileName,'.')) != NULL)
	{
		*optpos = '\0';
	}

	
	

	if (sscanf(sizepos,":%i",&size) != 1)
	{
		return -1;
	}

	*sizepos = '\0';	// concat the string again. <name>:<size> becomes <name><NULL><size> effecively making it <name>

	this->texture = glGenLists(256);
	if (this->texture == -1 || this->texture == 0)	// error occured while creating font
		return -1;


	newFont = CreateFont(	-size,				// Height Of Font ( NEW )
						0,				// Width Of Font
						0,				// Angle Of Escapement
						0,				// Orientation Angle
						opt_bold,			// Font Weight
						opt_italic,				// Italic
						opt_underline,				// Underline
						opt_strike,				// Strikeout
						ANSI_CHARSET,			// Character Set Identifier
						OUT_TT_PRECIS,			// Output Precision
						CLIP_DEFAULT_PRECIS,		// Clipping Precision
						ANTIALIASED_QUALITY,		// Output Quality
						FF_DONTCARE|DEFAULT_PITCH,	// Family And Pitch
						fileName);			// Font Name

	

	oldFont = (HFONT)SelectObject(hDC, newFont);		// Selects The Font We Want
	wglUseFontBitmaps(hDC, 0, 256, this->texture);			// Builds 256 Characters Starting At Character 0
	
	for (letter=0; letter<255; letter++)	// loop through all letters and extract their width and height
	{
		GetTextExtentPoint(hDC,(char*)&letter,1,&letterSize);
		fontWidth[letter] = letterSize.cx;
		fontHeight[letter] = letterSize.cy;
	}
	
	SelectObject(hDC, oldFont);				// Selects The Font We Want

	return 0;
}

Rendering is as simple as calling CallLists
glListBase(texture->texture);
glCallLists( strlen(t->getText()), GL_UNSIGNED_BYTE, t->getText());

How can I make the font seamless?

Share this post


Link to post
Share on other sites
Advertisement
This is just a random stab in the dark but have you tried changing

fontWidth[letter] = letterSize.cx;

to

fontWidth[letter] = letterSize.cx - 1;

?

Share this post


Link to post
Share on other sites
Just for you I did, but no.
The fontwidth array is for fetching the dimensions for a string. For example when aligning the string to the center, you need the size of the string. That's what the array does.

I've tried fiddling around with the parameters of the CreateFont function but no success. :(

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Just for you I did, but no.

awww. Thanks :).

Anyway. Perhaps the raster position is being advanced too far after drawing a character? In which case the problem may be with wglUseFontBitmaps.

One possible hack solution (if this is the case) would be:

Instead of calling the display lists all at once call one character at a time within a for loop and set the raster position back one or two pixels after every character e.g.


int rasterpos[4];
char* txt = t->getText();

glListBase(texture->texture);
for ( i=0; txt != 0; i++ )
{
glCallLists( 1, GL_UNSIGNED_BYTE, txt);
glGetIntegerv(GL_CURRENT_RASTER_POS, rasterpos)
glRasterPos3i(rasterpos[0]-1, rasterpos[1], rasterpos[2]);
}



Even if this doesn't work the results might (with luck) provide a hint as to what is going wrong.

Of course you could also try building the display lists yourself instead of using the wgl function but that's probably overkill just to enable underlined fonts :).

Share this post


Link to post
Share on other sites
I tried your snippet, but the problem remains.

I also tried moving the raster for every font seperately using the character width (from the array I told you about). No success.
So assuming I fetch the width of every character correctly, the bitmaps generated simply do not match. So, as you say, wglUseFontBitmaps is probably messing something up.
And writing my own font generator just for underlined fonts isn't worth the hassle at this moment.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!