Opengl fix: bitmaps having a width not multiple of 4 were incorrectly drawn.

This fix draws a "sub bitmap" having a width multiple of 4.
(The loss of 1 to 3 pixels in horizontal size should be not really noticeable)

(cherry picked from commit 3a02e54411)
This commit is contained in:
jean-pierre charras 2018-07-30 16:18:53 +02:00 committed by Seth Hillbrand
parent a43ec3e3f0
commit 99f25b0895
1 changed files with 19 additions and 12 deletions

View File

@ -121,21 +121,28 @@ GLuint GL_BITMAP_CACHE::cacheBitmap( const BITMAP_BASE* aBitmap )
bmp.w = aBitmap->GetSizePixels().x;
bmp.h = aBitmap->GetSizePixels().y;
// There are draw issues (incorrect rendering) with some w values.
// It happens when the w value is not a multiple of 4
// so we use only a sub image with a modified width
bmp.w -= bmp.w % 4;
GLuint textureID;
glGenTextures(1, &textureID);
uint8_t *buf = new uint8_t [ bmp.w * bmp.h * 3];
auto imgData = const_cast<BITMAP_BASE*>( aBitmap )->GetImageData();
for( int y=0; y < bmp.h; y++ )
for( int x = 0; x < bmp.w;x++)
for( int y = 0; y < bmp.h; y++ )
{
auto *p = buf + ( bmp.w * y + x ) * 3;
for( int x = 0; x < bmp.w; x++ )
{
uint8_t *p = buf + ( bmp.w * y + x ) * 3;
p[0] = imgData->GetRed( x, y );
p[1] = imgData->GetGreen( x, y );
p[2] = imgData->GetBlue( x, y );
}
}
glBindTexture( GL_TEXTURE_2D, textureID );