QOpenGLWidget OpenGL selection mode bug
Unsolved
General and Desktop
-
#include<QOpenGLWidget> #include<QOpenGLFunctions> #include<gl/GL.h> #include<gl/GLU.h> #include<QMouseEvent> #include<QDebug> class OpenGLWidget : public QOpenGLWidget, protected QOpenGLFunctions { protected: void initializeGL() override { this->initializeOpenGLFunctions(); } void paintGL() override { glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-10, 10, -10, 10, 1, 10); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0, 0, 1.5, 0, 0, 0, 0, 1, 0); glLoadName(0); glColor4d(1, 0, 0, 1); glRectd(0, 0, 1, 1); glLoadName(1); glColor4d(0, 1, 0, 1); glRectd(1, 1, 2, 2); glLoadName(2); glColor4d(0, 0, 1, 1); glRectd(2, 2, 3, 3); glLoadName(2); glColor4d(0, 0, 1, 1); glRectd(3, 3, 4, 4); glFlush(); } void resizeGL(int width, int height) override { glViewport(0, 0, width, height); } protected: void mousePressEvent(QMouseEvent* event) override { } void mouseReleaseEvent(QMouseEvent* event) override { GLuint selectBuf[512]; glSelectBuffer(512, selectBuf); glRenderMode(GL_SELECT); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); GLint viewport[4]; viewport[0] = 0; viewport[1] = 0; viewport[2] = this->width(); viewport[3] = this->height(); gluPickMatrix(11, 11, 3.0, 3.0, viewport);//第二个参数坐标系反的 glFrustum(-10, 10, -10, 10, 1, 10); glInitNames(); glPushName(0); glLoadName(0); glColor4d(1, 0, 0, 1); glRectd(0, 0, 1, 1); glLoadName(1); glColor4d(0, 1, 0, 1); glRectd(1, 1, 2, 2); glLoadName(2); glColor4d(0, 0, 1, 1); glRectd(2, 2, 3, 3); glLoadName(2); glColor4d(0, 0, 1, 1); glRectd(3, 3, 4, 4); glMatrixMode(GL_PROJECTION); glPopMatrix(); glFlush(); int hits = glRenderMode(GL_RENDER); qDebug() << "selectBuf"; qDebug() << hits << "hits"; int index = 0; for (int i = 0; i < hits; i++) { int names = selectBuf[index]; qDebug() << "names" << selectBuf[index++]; qDebug() << selectBuf[index++] / 4294967295.0; qDebug() << selectBuf[index++] / 4294967295.0; for (int j = 0; j < names; j++) { qDebug() << selectBuf[index++]; } } } };
Any value in the parameter setting of glupickmatrix will select all.
In perspective projection, no matter where you click, glrendermode returns four hits.
The orthographic projection is all right.
It can be used normally without QT.
So I think it's a bug in QT.
I hope someone will reply to me as soon as possible.