16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 */ |
17 */ |
18 |
18 |
19 #include <glm/ext/matrix_transform.hpp> |
19 #include <glm/ext/matrix_transform.hpp> |
20 #include <glm/ext/matrix_clip_space.hpp> |
20 #include <glm/ext/matrix_clip_space.hpp> |
|
21 #include <QOpenGLFramebufferObject> |
21 #include <QPainter> |
22 #include <QPainter> |
22 #include <GL/glu.h> |
23 #include <GL/glu.h> |
23 #include <QMouseEvent> |
24 #include <QMouseEvent> |
24 #include <QMessageBox> |
25 #include <QMessageBox> |
25 #include <QAbstractButton> |
26 #include <QAbstractButton> |
459 // and multiply the pixel positions by the screen pixel scaling factor. |
460 // and multiply the pixel positions by the screen pixel scaling factor. |
460 where *= this->devicePixelRatioF(); |
461 where *= this->devicePixelRatioF(); |
461 const gl::RenderStyle oldRenderStyle = this->renderPreferences.style; |
462 const gl::RenderStyle oldRenderStyle = this->renderPreferences.style; |
462 this->renderPreferences.style = gl::RenderStyle::PickScene; |
463 this->renderPreferences.style = gl::RenderStyle::PickScene; |
463 this->makeCurrent(); |
464 this->makeCurrent(); |
|
465 QOpenGLFramebufferObject fbo{this->width(), this->height(), QOpenGLFramebufferObject::CombinedDepthStencil}; |
|
466 fbo.bind(); |
464 this->renderScene(); |
467 this->renderScene(); |
465 std::array<GLubyte, 3> data; |
468 std::array<GLubyte, 3> data; |
466 this->checkForGLErrors(); |
469 this->checkForGLErrors(); |
467 glfunc.glReadPixels(where.x(), where.y(), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &data[0]); |
470 glfunc.glReadPixels(where.x(), where.y(), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &data[0]); |
468 this->checkForGLErrors(); |
471 this->checkForGLErrors(); |
|
472 fbo.release(); |
469 this->renderPreferences.style = oldRenderStyle; |
473 this->renderPreferences.style = oldRenderStyle; |
470 this->update(); |
|
471 return gl::idFromColor(data); |
474 return gl::idFromColor(data); |
472 } |
475 } |
473 |
476 |
474 /** |
477 /** |
475 * @brief Changes the color of rendered fragments |
478 * @brief Changes the color of rendered fragments |