Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPainter break coordinate system in OpenGl

QPainter break coordinate system in OpenGl

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 849 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zloi_templar
    wrote on last edited by zloi_templar
    #1

    Hello
    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?

    1 Reply Last reply
    0
    • SebastienLS Offline
      SebastienLS Offline
      SebastienL
      wrote on last edited by
      #2

      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 is

      SIrrlichtCreationParameters createParams; 
      createParams.WindowId = (void *) myQTWidget->winId();".
      

      Sébastien L.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Shouldn't you be using beginNativePainting and endNativePainting ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        Z 1 Reply Last reply
        0
        • Z Offline
          Z Offline
          zloi_templar
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            Shouldn't you be using beginNativePainting and endNativePainting ?

            Z Offline
            Z Offline
            zloi_templar
            wrote on last edited by
            #5

            @SGaist
            hi, i'm tried to used it, such result

            SebastienLS 1 Reply Last reply
            0
            • Z zloi_templar

              @SGaist
              hi, i'm tried to used it, such result

              SebastienLS Offline
              SebastienLS Offline
              SebastienL
              wrote on last edited by
              #6

              @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();".

              Z 1 Reply Last reply
              1
              • SebastienLS SebastienL

                @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();".

                Z Offline
                Z Offline
                zloi_templar
                wrote on last edited by zloi_templar
                #7

                @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

                1. I draw box and object by OpenGl
                2. I draw objects names by Qpainter
                3. I draw point on object by click (doesn't work due to previous item, if i comment item 2, all work fine)
                1 Reply Last reply
                0
                • Z Offline
                  Z Offline
                  zloi_templar
                  wrote on last edited by
                  #8

                  solved

                  glPushAttrib(GL_ALL_ATTRIB_BITS);
                  glMatrixMode(GL_PROJECTION);
                  glPushMatrix();
                  glMatrixMode(GL_MODELVIEW);
                  glPushMatrix();
                  

                  /QPainter/

                  glMatrixMode(GL_MODELVIEW);
                  glPopMatrix();
                  glMatrixMode(GL_PROJECTION);
                  glPopMatrix();
                  glPopAttrib();
                  
                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved