Hello,
Recently I ran into a weird problem when I was attempting to use GL to generate a texture atlas of font characters using freetype2. The character widths would be odd numbers like 21 pixels, for example. I then created a temporary buffer to copy the character into while at the same time vertically flipping it and then used glTexSubImage2D to copy the temporary image buffer onto the main texture at the right position.
I began seeing skewing, like in this image:
At first I thought it was perhaps a freetype bug as even if I passed the freetype buffer through directly, it would be skewed in the same way (albeit upside-down). I noticed that the width of the character factored into whether or not it was skewed… a character which freetype rendered into an image buffer with a width that was a multiple of 4 was unskewed. Any other value produced skewing.
Eventually with help from some friendly users at gamedev.net I found that by padding the row width of my temporary image buffer up to the nearest multiple of 4, the skewing went away. In the case of the 21-pixel-wide character glyph I’d create a temporary image 24 pixels wide, then map the freetype glyph into that buffer. I resolved the issue more completely by creating my temporary image as RGBA instead (as previously I was working with 1-byte pixels).
So my question is, why? Does this have to do with the glPixelStore method? Or is it something more inherent to GL?
There’s no issue to resolve now, I have code which does what I want. I just like to try and understand the why.
Thanks!