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 draws text quads counterclockwise and other primitives clockwise. Bug or intentional?

QPainter draws text quads counterclockwise and other primitives clockwise. Bug or intentional?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.6k 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.
  • A Offline
    A Offline
    amdreallyfast
    wrote on 1 Oct 2016, 02:12 last edited by
    #1

    Using Qt 5.6.0 on Windows 10.

    QPainter draws the quads for text bitmaps \counterclockwise, while primitives like ellipses and the quads for QPixmap draw clockwise. Result found on QOpenGLWidget.

    Is this intentional?

    Ex: I want to draw a 3D scene and then try to draw a framerate counter on top of it with QPainter's text functionality.

    Justification:

    • According to glCullFace, OpenGL face culling defaults to culling the back face, so front faces are shown but back faces are not.
    • According to glFrontFace, OpenGL defines a "front face" as counterclockwise polygons.
    • Therefore, if face culling is enabled in an OpenGL-running widget, it will default to culling clockwise (back face) polygons and anything that uses them.

    Demonstration code:
    See the example “2D Painting Example” in Qt Creator (I’m running Qt 5.6.0). This example uses a QPainter object to draw text and rotating elipses on a QOpenGLWidget.

    • Add override of initializeGL() to GLwidget.
    • In source file, add function:
    #include <qopenglfunctions_2_1.h>
    void GLWidget::initializeGL()
    {
        QOpenGLFunctions_2_1 *f = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_2_1>();
        f->glEnable(GL_CULL_FACE);
        //f->glCullFace(GL_FRONT);      // uncomment to cull the text and show the rotating elipses
    }
    
    • Run the program. The text "Qt" draws but the elipses don't. Uncomment glCullFace(GL_FRONT) to reverse the effect and show the elipses but not the text.
    • Now try drawing a pixmap after culling is turned on. The following won’t draw if culling is turned on and it is culling back faces (clockwise polygons).
    void GLWidget::paintGL()
    {
        QPixmap p(myImageFilePath);
        QPainter painter(this);
        painter.drawPixmap(0, 0, p.scaled(this->size());
    }
    
    • To draw a QPixmap when back faces are being culled, you have to do this:
    void GLWidget::paintGL()
    {
        QPixmap p(myImageFilePath);
        QOpenGLFunctions_2_1 *f = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_2_1>();
        GLBoolean faceCullingIsOn;
        
        // save current culling state
        f->glGetBooleanv(GL_CULL_FACE, &faceCullingIsOn);
        f->glDisable(GL_CULL_FACE);
        QPainter painter(this);
        painter.drawPixmap(0, 0, p.scaled(this->size());
        if (faceCullingIsOn == GL_TRUE)
        {
            // turn it back on
            f->glEnable(GL_CULL_FACE);
        }
    }
    

    Bug or intentional? This isn't a show-stopper for me but it did cause some grief.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on 1 Oct 2016, 11:03 last edited by
      #2

      Hi! Please ask this the framework developers on the mailing list (http://lists.qt-project.org/mailman/listinfo). This forum is more user oriented thus it's unlikely that the right people will find your question here :-)

      A 1 Reply Last reply 2 Oct 2016, 20:29
      2
      • ? A Former User
        1 Oct 2016, 11:03

        Hi! Please ask this the framework developers on the mailing list (http://lists.qt-project.org/mailman/listinfo). This forum is more user oriented thus it's unlikely that the right people will find your question here :-)

        A Offline
        A Offline
        amdreallyfast
        wrote on 2 Oct 2016, 20:29 last edited by
        #3

        @Wieland Sorry for the late reply. Where are the framework developers? Would they be under the Interest or Development lists?

        ? 1 Reply Last reply 2 Oct 2016, 20:32
        0
        • A amdreallyfast
          2 Oct 2016, 20:29

          @Wieland Sorry for the late reply. Where are the framework developers? Would they be under the Interest or Development lists?

          ? Offline
          ? Offline
          A Former User
          wrote on 2 Oct 2016, 20:32 last edited by
          #4

          @amdreallyfast Sorry, I posted the wrong link. "Interest" is the right one: http://lists.qt-project.org/mailman/listinfo/interest

          A 1 Reply Last reply 2 Oct 2016, 20:46
          0
          • ? A Former User
            2 Oct 2016, 20:32

            @amdreallyfast Sorry, I posted the wrong link. "Interest" is the right one: http://lists.qt-project.org/mailman/listinfo/interest

            A Offline
            A Offline
            amdreallyfast
            wrote on 2 Oct 2016, 20:46 last edited by
            #5

            @Wieland I just subscribed, but it is a mailing list and not a regular forum, so I don't know the usual practice. In a forum you create a thread, but for a mailing list to I just send an email to everyone on the list?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 2 Oct 2016, 20:57 last edited by
              #6

              Hi,

              No, you send a mail to the mailing list address. Everybody subscribed will receive it.

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

              1 Reply Last reply
              0

              5/6

              2 Oct 2016, 20:46

              • Login

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