Issue with UI TTF Rendering
Opened this issue · 1 comments
Everything seems to work fine, build and run is ok but the writings are a horrible rendering artifact made by retorts lines in columns. What could be the issue? Maybe something about compatibility? I'm testing on the latest Ubuntu with a Radeon GPU.
This sounds like the problem I also encountered, and I found that the implementation of Texture::CreateFromSurface
is not completely correct - it works when I boot into Windows, but not in Ubuntu.
The problem is here:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mWidth, mHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, surface->pixels);
where:
mWidth = surface->w;
The pixel data in the rendered surface is in fact NOT surface->w * surface->h
pixels, as might be expected, but instead you should use:
mWidth = surface->pitch/4;
The explanation (as I understand it) is that the rendered surface is padded by some bytes in order to reach a "nice" width (seems to be a factor of 16 or something like that), so each row in the pixel data may in fact be longer than "surface->w". And since surface->pitch is defined as number of bytes per row, it should be divided by the number of bytes per pixel (4 channels, i.e. RGBA).