OPENGL_GAL: draw BITMAP_BASE: fix incorrect rendering of mirrored bitmaps

The vertical mirror was not working.
This commit is contained in:
jean-pierre charras 2023-04-23 16:00:05 +02:00
parent f47f44350d
commit 31b30cef96
3 changed files with 23 additions and 12 deletions

View File

@ -41,7 +41,8 @@ BITMAP_BASE::BITMAP_BASE( const VECTOR2I& pos )
m_ppi = 300; // the bitmap definition. the default is 300PPI
m_pixelSizeIu = 254000.0 / m_ppi; // a pixel size value OK for bitmaps using 300 PPI
// for Eeschema which uses currently 254000PPI
m_isMirrored = false;
m_isMirroredX = false;
m_isMirroredY = false;
m_rotation = ANGLE_0;
}
@ -51,7 +52,8 @@ BITMAP_BASE::BITMAP_BASE( const BITMAP_BASE& aSchBitmap )
m_scale = aSchBitmap.m_scale;
m_ppi = aSchBitmap.m_ppi;
m_pixelSizeIu = aSchBitmap.m_pixelSizeIu;
m_isMirrored = aSchBitmap.m_isMirrored;
m_isMirroredX = aSchBitmap.m_isMirroredX;
m_isMirroredY = aSchBitmap.m_isMirroredY;
m_rotation = aSchBitmap.m_rotation;
m_image = nullptr;
@ -115,7 +117,8 @@ void BITMAP_BASE::ImportData( BITMAP_BASE* aItem )
m_scale = aItem->m_scale;
m_ppi = aItem->m_ppi;
m_pixelSizeIu = aItem->m_pixelSizeIu;
m_isMirrored = aItem->m_isMirrored;
m_isMirroredX = aItem->m_isMirroredX;
m_isMirroredY = aItem->m_isMirroredY;
m_rotation = aItem->m_rotation;
}
@ -414,7 +417,11 @@ void BITMAP_BASE::Mirror( bool aVertically )
m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONX, resX);
m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONY, resY);
m_isMirrored = !m_isMirrored;
if( aVertically )
m_isMirroredY = !m_isMirroredY;
else
m_isMirroredX = !m_isMirroredX;
rebuildBitmap( false );
}
}

View File

@ -1427,21 +1427,23 @@ void OPENGL_GAL::DrawBitmap( const BITMAP_BASE& aBitmap, double alphaBlend )
glActiveTexture( GL_TEXTURE0 );
glBindTexture( GL_TEXTURE_2D, texture_id );
float texStartX = aBitmap.IsMirrored() ? 1.0 : 0.0;
float texEndX = aBitmap.IsMirrored() ? 0.0 : 1.0;
float texStartX = aBitmap.IsMirroredX() ? 1.0 : 0.0;
float texEndX = aBitmap.IsMirroredX() ? 0.0 : 1.0;
float texStartY = aBitmap.IsMirroredY() ? 1.0 : 0.0;
float texEndY = aBitmap.IsMirroredY() ? 0.0 : 1.0;
glBegin( GL_QUADS );
glColor4f( 1.0, 1.0, 1.0, alpha );
glTexCoord2f( texStartX, 0.0 );
glTexCoord2f( texStartX, texStartY );
glVertex3f( v0.x, v0.y, m_layerDepth );
glColor4f( 1.0, 1.0, 1.0, alpha );
glTexCoord2f( texEndX, 0.0 );
glTexCoord2f( texEndX, texStartY);
glVertex3f( v1.x, v0.y, m_layerDepth );
glColor4f( 1.0, 1.0, 1.0, alpha );
glTexCoord2f( texEndX, 1.0 );
glTexCoord2f( texEndX, texEndY);
glVertex3f( v1.x, v1.y, m_layerDepth );
glColor4f( 1.0, 1.0, 1.0, alpha );
glTexCoord2f( texStartX, 1.0 );
glTexCoord2f( texStartX, texEndY);
glVertex3f( v0.x, v1.y, m_layerDepth );
glEnd();

View File

@ -210,7 +210,8 @@ public:
void ConvertToGreyscale();
bool IsMirrored() const { return m_isMirrored; }
bool IsMirroredX() const { return m_isMirroredX; }
bool IsMirroredY() const { return m_isMirroredY; }
EDA_ANGLE Rotation() const { return m_rotation; }
/**
@ -249,7 +250,8 @@ private:
// Usually does not change
int m_ppi; // the bitmap definition. the default is 300PPI
KIID m_imageId;
bool m_isMirrored; // Used for OpenGL rendering only
bool m_isMirroredX; // Used for OpenGL rendering only
bool m_isMirroredY; // Used for OpenGL rendering only
EDA_ANGLE m_rotation; // Used for OpenGL rendering only
};