I wanna select point on object by click
It successfully realized
this->camera()->convertClickToLine(point, orig, dir);
bool found;
selectedPoint = this->camera()->pointUnderPixel(point, found);
if (selectedName() >= 0) {
glColor3f(0.9f, 0.2f, 0.1f);
glBegin(GL_POINTS);
glVertex3f(selectedPoint.x, selectedPoint.y, selectedPoint.z);
glEnd();
}
example of selectable object:
glBegin(GL_TRIANGLES);
glColor3f(0.5,0,0);
glVertex3f(xmin,ymin,zmin);
glVertex3f(xmin + (xmax-xmin)/2,ymin+(ymax-ymin)/2, zmin+(zmax-zmin)/2);
glVertex3f(xmax,ymin,zmin);
glEnd();
But if i start using QPainter, selectedPoint change coords to smth wrong
QPainter painter(this);
painter.setPen(Qt::black);
painter.setFont(QFont("Helvetica", 8));
painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
painter.drawText(textPosX + 10, textPosY, text);
painter.setBrush(QBrush(Qt::black, Qt::SolidPattern));
painter.drawEllipse(QPoint(textPosX, textPosY), 2, 2);
painter.end();
what should i do?
my steps:
I draw box and object by OpenGl
I draw objects names by Qpainter
I draw point on object by click (doesn't work due to previous item, if i comment item 2, all work fine)
solved
glPushAttrib(GL_ALL_ATTRIB_BITS);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
/QPainter/
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glPopAttrib();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.