QPainter break coordinate system in OpenGl
-
Hello
I wanna select point on object by click
It successfully realizedthis->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?
-
Hi,
I used a bit Irrlicht & openGL in the few previous weeks, and I can suggest you to check what is wrong on the new coordinates. I have a lot of problems with a Y shift due to the window toolbar (something like 20 pixels shift all the time), and other problems with the QT object ID which is painted by OpenGL at initialization. By example painting with OpengGL the floating dockwidget window ID will give you wrong coordinates, instead of give OpenGL the QWidget ID contains in the floating window, which will give you the good coordinates.
In Irrlicht the critical command isSIrrlichtCreationParameters createParams; createParams.WindowId = (void *) myQTWidget->winId();".
Sébastien L.
-
Hi,
Shouldn't you be using beginNativePainting and endNativePainting ?
-
This post is deleted!
-
Hi,
Shouldn't you be using beginNativePainting and endNativePainting ?
@SGaist
hi, i'm tried to used it, such result -
@SGaist
hi, i'm tried to used it, such result@zloi_templar
Maybe you will find your answer but I think you understood from looking on the internet that using OpenGL with Qt may be problematic, and using QPainter at the same time as OpenGL to draw is worse. Maybe staying on OpenGL would be more suitable, Irrlicht is a very light free library and allows you to draw a lot of things (either on the screen with draw() or in the 3D space with IBillboardTextSceneNode).
Qt with Irrlicht tutorial
You can draw inside a specific Widget too with the "createParams.WindowId = (void *) myQTWidget->winId();". -
@zloi_templar
Maybe you will find your answer but I think you understood from looking on the internet that using OpenGL with Qt may be problematic, and using QPainter at the same time as OpenGL to draw is worse. Maybe staying on OpenGL would be more suitable, Irrlicht is a very light free library and allows you to draw a lot of things (either on the screen with draw() or in the 3D space with IBillboardTextSceneNode).
Qt with Irrlicht tutorial
You can draw inside a specific Widget too with the "createParams.WindowId = (void *) myQTWidget->winId();".@SebastienL
Ty for answer
Kk, i will try to use other library
And i need to draw not in different Widgets, all in one, step by step- 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();