From 31b30cef96cdc882c012b7fbbcd9956f8a3c53e0 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 23 Apr 2023 16:00:05 +0200 Subject: [PATCH] OPENGL_GAL: draw BITMAP_BASE: fix incorrect rendering of mirrored bitmaps The vertical mirror was not working. --- common/bitmap_base.cpp | 15 +++++++++++---- common/gal/opengl/opengl_gal.cpp | 14 ++++++++------ include/bitmap_base.h | 6 ++++-- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/common/bitmap_base.cpp b/common/bitmap_base.cpp index 99c8f38fd4..5c4586ca04 100644 --- a/common/bitmap_base.cpp +++ b/common/bitmap_base.cpp @@ -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 ); } } diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index a5a1b0d312..9b3e506cfb 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -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(); diff --git a/include/bitmap_base.h b/include/bitmap_base.h index 558f18d86d..61c583b9c0 100644 --- a/include/bitmap_base.h +++ b/include/bitmap_base.h @@ -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 };