From deb8ba223752d7b4a9aa85c4c8e608d01b792455 Mon Sep 17 00:00:00 2001 From: Christoph Rackwitz Date: Sun, 16 Dec 2018 05:50:32 +0100 Subject: [PATCH] fix for #4990: highgui w32 ogl: correct calculation of image coordinates from window coordinates --- modules/highgui/src/window_w32.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/modules/highgui/src/window_w32.cpp b/modules/highgui/src/window_w32.cpp index e7141cb82c..130807e9e6 100644 --- a/modules/highgui/src/window_w32.cpp +++ b/modules/highgui/src/window_w32.cpp @@ -66,6 +66,7 @@ #include #include "opencv2/highgui.hpp" #include +#include "opencv2/core/opengl.hpp" #endif static const char* trackbar_text = @@ -1489,7 +1490,20 @@ MainWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) GetClientRect( window->hwnd, &rect ); SIZE size = {0,0}; - icvGetBitmapData( window, &size, 0, 0 ); +#ifdef HAVE_OPENGL + if (window->useGl) + { + cv::ogl::Texture2D* texObj = static_cast(window->glDrawData); + size.cx = texObj->cols(); + size.cy = texObj->rows(); + } + else + { + icvGetBitmapData(window, &size, 0, 0); + } +#else + icvGetBitmapData(window, &size, 0, 0); +#endif window->on_mouse( event, pt.x*size.cx/MAX(rect.right - rect.left,1), pt.y*size.cy/MAX(rect.bottom - rect.top,1), flags, @@ -1683,7 +1697,21 @@ static LRESULT CALLBACK HighGUIProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM SIZE size = {0, 0}; GetClientRect( window->hwnd, &rect ); + +#ifdef HAVE_OPENGL + if (window->useGl) + { + cv::ogl::Texture2D* texObj = static_cast(window->glDrawData); + size.cx = texObj->cols(); + size.cy = texObj->rows(); + } + else + { + icvGetBitmapData(window, &size, 0, 0); + } +#else icvGetBitmapData( window, &size, 0, 0 ); +#endif window->on_mouse( event, pt.x*size.cx/MAX(rect.right - rect.left,1), pt.y*size.cy/MAX(rect.bottom - rect.top,1), flags,