From f7a232d6dac0a3b13540a523d171d2394ab3872e Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Thu, 5 Feb 2015 13:29:32 +0000 Subject: [PATCH] fix unproject and addPointMode for highres displays --- Fltk/openglWindow.cpp | 5 ++++- Graphics/drawContext.cpp | 21 +++++++++++++-------- Graphics/drawContext.h | 6 +++--- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Fltk/openglWindow.cpp b/Fltk/openglWindow.cpp index d4ace764fd..0b59e8d18d 100644 --- a/Fltk/openglWindow.cpp +++ b/Fltk/openglWindow.cpp @@ -215,7 +215,10 @@ void openglWindow::draw() _ctx->draw3d(); glColor4ubv((GLubyte *) & CTX::instance()->color.fg); - glPointSize((float)CTX::instance()->geom.pointSize); + float ps = CTX::instance()->geom.pointSize; + if(_ctx->isHighResolution()) + ps *= CTX::instance()->highResolutionPointSizeFactor; + glPointSize(ps); glBegin(GL_POINTS); glVertex3d(_point[0], _point[1], _point[2]); glEnd(); diff --git a/Graphics/drawContext.cpp b/Graphics/drawContext.cpp index 2b950e203f..beffcb054f 100644 --- a/Graphics/drawContext.cpp +++ b/Graphics/drawContext.cpp @@ -755,21 +755,26 @@ void drawContext::initPosition() // Takes a cursor position in window coordinates and returns the line (given by // a point and a unit direction vector), in real space, that corresponds to that // cursor position -void drawContext::unproject(double x, double y, double p[3], double d[3]) +void drawContext::unproject(double winx, double winy, double p[3], double d[3]) { + if(isHighResolution()){ + winx *= 2; // true pixels + winy *= 2; + } + GLint vp[4]; glGetIntegerv(GL_VIEWPORT, vp); - y = vp[3] - y; + winy = vp[3] - winy; GLdouble x0, y0, z0, x1, y1, z1; // we use the stored model and proj matrices instead of directly // getGetDouble'ing the matrices since unproject can be called in or after // draw2d - if(!gluUnProject(x, y, 0.0, model, proj, vp, &x0, &y0, &z0)) + if(!gluUnProject(winx, winy, 0.0, model, proj, vp, &x0, &y0, &z0)) Msg::Warning("unproject1 failed"); - if(!gluUnProject(x, y, 1.0, model, proj, vp, &x1, &y1, &z1)) + if(!gluUnProject(winx, winy, 1.0, model, proj, vp, &x1, &y1, &z1)) Msg::Warning("unproject2 failed"); p[0] = x0; @@ -784,24 +789,24 @@ void drawContext::unproject(double x, double y, double p[3], double d[3]) d[2] /= len; } -void drawContext::viewport2World(double win[3], double xyz[3]) +void drawContext::viewport2World(double vp[3], double xyz[3]) { GLint viewport[4]; GLdouble model[16], proj[16]; glGetIntegerv(GL_VIEWPORT, viewport); glGetDoublev(GL_PROJECTION_MATRIX, proj); glGetDoublev(GL_MODELVIEW_MATRIX, model); - gluUnProject(win[0], win[1], win[2], model, proj, viewport, &xyz[0], &xyz[1], &xyz[2]); + gluUnProject(vp[0], vp[1], vp[2], model, proj, viewport, &xyz[0], &xyz[1], &xyz[2]); } -void drawContext::world2Viewport(double xyz[3], double win[3]) +void drawContext::world2Viewport(double xyz[3], double vp[3]) { GLint viewport[4]; GLdouble model[16], proj[16]; glGetIntegerv(GL_VIEWPORT, viewport); glGetDoublev(GL_PROJECTION_MATRIX, proj); glGetDoublev(GL_MODELVIEW_MATRIX, model); - gluProject(xyz[0], xyz[1], xyz[2], model, proj, viewport, &win[0], &win[1], &win[2]); + gluProject(xyz[0], xyz[1], xyz[2], model, proj, viewport, &vp[0], &vp[1], &vp[2]); } class hit{ diff --git a/Graphics/drawContext.h b/Graphics/drawContext.h index ef2d1e9ede..183790c653 100644 --- a/Graphics/drawContext.h +++ b/Graphics/drawContext.h @@ -191,9 +191,9 @@ class drawContext { void initProjection(int xpick=0, int ypick=0, int wpick=0, int hpick=0); void initRenderModel(); void initPosition(); - void unproject(double x, double y, double p[3], double d[3]); - void viewport2World(double win[3], double xyz[3]); - void world2Viewport(double xyz[3], double win[3]); + void unproject(double winx, double winy, double p[3], double d[3]); + void viewport2World(double vp[3], double xyz[3]); + void world2Viewport(double xyz[3], double vp[3]); bool select(int type, bool multiple, bool mesh, int x, int y, int w, int h, std::vector<GVertex*> &vertices, std::vector<GEdge*> &edges, std::vector<GFace*> &faces, std::vector<GRegion*> ®ions, -- GitLab