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)
This commit is contained in:
jean-pierre charras 2018-07-30 16:18:53 +02:00
parent 6e9990449f
commit 3a02e54411
1 changed files with 19 additions and 12 deletions

View File

@ -121,6 +121,11 @@ 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);
@ -128,14 +133,16 @@ GLuint GL_BITMAP_CACHE::cacheBitmap( const BITMAP_BASE* aBitmap )
auto imgData = const_cast<BITMAP_BASE*>( aBitmap )->GetImageData();
for( int y = 0; y < bmp.h; y++ )
{
for( int x = 0; x < bmp.w; x++ )
{
auto *p = buf + ( bmp.w * y + x ) * 3;
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 );