Qt3D: How to render a mesh in wireframe mode using Qt C++?

后端 未结 1 1437
借酒劲吻你
借酒劲吻你 2020-12-24 13:30

Qt3D documentation is increasing but still lacking some information especially on how to do things without Qml/QtQuick. After heavily searching the web about rendering a mes

相关标签:
1条回答
  • 2020-12-24 13:39

    The OP is interested on write a shader program, so its necessary to write OpenGL in Qt, right? Like in https://doc.qt.io/qt-5/qtgui-openglwindow-example.html and https://doc.qt.io/qt-5/qtopengl-hellogl2-example.htm.

    There is a simple shader example on https://doc.qt.io/qt-5/qopenglshaderprogram.html

    program.addShaderFromSourceCode(QOpenGLShader::Vertex,
        "attribute highp vec4 vertex;\n"
        "uniform highp mat4 matrix;\n"
        "void main(void)\n"
        "{\n"
        "   gl_Position = matrix * vertex;\n"
        "}");
    program.addShaderFromSourceCode(QOpenGLShader::Fragment,
        "uniform mediump vec4 color;\n"
        "void main(void)\n"
        "{\n"
        "   gl_FragColor = color;\n"
        "}");
    

    From https://learnopengl.com/Getting-started/Hello-Triangle

    To draw your triangles in wireframe mode, you can configure how OpenGL draws its primitives via glPolygonMode(GL_FRONT_AND_BACK, GL_LINE). The first argument says we want to apply it to the front and back of all triangles and the second line tells us to draw them as lines. Any subsequent drawing calls will render the triangles in wireframe mode until we set it back to its default using glPolygonMode(GL_FRONT_AND_BACK, GL_FILL).

    And from https://learnopengl.com/Advanced-OpenGL/Advanced-GLSL

    The gl_FrontFacing variable tells us if the current fragment is part of a front-facing or a back-facing face. We could, for example, decide to output different colors for all back faces.

    0 讨论(0)
提交回复
热议问题