Distorted freetype fonts

Started by
14 comments, last by GreyHound 13 years, 2 months ago
For win32 bitmaps, each scanline is stored as a multiple of 4(bytes). Assuming we're talking about a 24bpp bitmap, it looks like your calculating each pixel wrong. Try something like this.
BMPPixel GetBMPPixel( BMP* Bitmap, int x, int y ){	DWORD BytesPerLine = Bitmap->Width * 3;	DWORD PaddingPerLine = 0;	if( BytesPerLine % 4 != 0 )	{		PaddingPerLine = 4 - (BytesPerLine % 4);	}	return *(BMPPixel*)&Bitmap->PixelData[(x * 3) + y * (BytesPerLine + PaddingPerLine)];}


It also looks like your buffer may be to small. Again assuming 24bpp bitmaps, it should be this size
unsigned char* bitmapBuffer = new unsigned char[bitmap.width * bitmap.rows * 3];



If that is the case, than this might even work.
bitmapBuffer[(j * 3) + i * bitmap.width] = bitmap.buffer[(j * 3) + i * bitmap.width];


The reason your code my work for some glyphs may be due to the glyphs already being a multiple of 4. So there is no need for padding. The diagonal-looking figure you have practically screams some sort of offset issue.
Advertisement
Quote:Original post by fitfool
It also looks like your buffer may be to small. Again assuming 24bpp bitmaps, it should be this size


There are no colors. The stuff that comes out of freetype2 is grayscale and the OpenGL command he posted earlier to draw the glyph was also grayscale.
Quote:Original post by fitfool
It also looks like your buffer may be to small. Again assuming 24bpp bitmaps, it should be this size
*** Source Snippet Removed ***


If that is the case, than this might even work.
*** Source Snippet Removed ***

The reason your code my work for some glyphs may be due to the glyphs already being a multiple of 4. So there is no need for padding. The diagonal-looking figure you have practically screams some sort of offset issue.


This is true for sub-pixel rendering.

If you look close at the debug results, all widths with a multiple of 4 display correctly. Try to increase the width so it meets a multiple of 4, someone above posted the code I think.
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
Ok!

Indeed the issue was padding related but the problem itself is due to the way glDrawPixels interprets the bitmap's rows. "By default, these pixels are taken from adjacent memory locations, except that after all width pixels are read, the read pointer is advanced to the next four-byte boundary.". A call to glPixelStorei(GL_UNPACK_ALIGNMENT, 1) solves it all.

Thanks for the help! ;)
Quote:Original post by Taylor001
Ok!

Indeed the issue was padding related but the problem itself is due to the way glDrawPixels interprets the bitmap's rows. "By default, these pixels are taken from adjacent memory locations, except that after all width pixels are read, the read pointer is advanced to the next four-byte boundary.". A call to glPixelStorei(GL_UNPACK_ALIGNMENT, 1) solves it all.

Thanks for the help! ;)


Man that one always pops up when I'm not expecting it.

A call to glPixelStorei(GL_UNPACK_ALIGNMENT, 1) solves it all.

Thanks for the help! ;)


Thanks, great help.


In my case i had to use:
glPixelStorei(GL_UNPACK_ALIGNMENT, 2);

This topic is closed to new replies.

Advertisement