Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



  • 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.



  • 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 :-)



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



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



  • @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?


  • Lifetime Qt Champion

    Hi,

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


Log in to reply