grbl 的pc端软件candle

void GLWidget::paintEvent(QPaintEvent *pe) {
    Q_UNUSED(pe)
#endif
    QPainter painter(this);

    // Segment counter
    int vertices = 0;

    painter.beginNativePainting();

    // Clear viewport
    glClearColor(m_colorBackground.redF(), m_colorBackground.greenF(), m_colorBackground.blueF(), 1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Shader drawable points
    glEnable(GL_PROGRAM_POINT_SIZE);

    // Update settings
    if (m_antialiasing) {
        if (m_msaa) glEnable(GL_MULTISAMPLE); else {
            glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
            glEnable(GL_LINE_SMOOTH);
            glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
            glEnable(GL_POINT_SMOOTH);

            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
            glEnable(GL_BLEND);
        }
    }
    if (m_zBuffer) glEnable(GL_DEPTH_TEST);

    if (m_shaderProgram) {
        // Draw 3d
        m_shaderProgram->bind();

        // Set modelview-projection matrix
        m_shaderProgram->setUniformValue("mvp_matrix", m_projectionMatrix * m_viewMatrix);
        m_shaderProgram->setUniformValue("mv_matrix", m_viewMatrix);

        // Update geometries in current opengl context
        foreach (ShaderDrawable *drawable, m_shaderDrawables)
            if (drawable->needsUpdateGeometry()) drawable->updateGeometry(m_shaderProgram);

        // Draw geometries
        foreach (ShaderDrawable *drawable, m_shaderDrawables) {
            drawable->draw(m_shaderProgram);
            if (drawable->visible()) vertices += drawable->getVertexCount();
        }

        m_shaderProgram->release();
    }

    // Draw 2D
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_MULTISAMPLE);
    glDisable(GL_LINE_SMOOTH);
    glDisable(GL_BLEND);

    painter.endNativePainting();

    QPen pen(m_colorText);
    painter.setPen(pen);

    double x = 10;
    double y = this->height() - 60;

    painter.drawText(QPoint(x, y), QString("X: %1 ... %2").arg(m_xMin, 0, 'f', 3).arg(m_xMax, 0, 'f', 3));
    painter.drawText(QPoint(x, y + 15), QString("Y: %1 ... %2").arg(m_yMin, 0, 'f', 3).arg(m_yMax, 0, 'f', 3));
    painter.drawText(QPoint(x, y + 30), QString("Z: %1 ... %2").arg(m_zMin, 0, 'f', 3).arg(m_zMax, 0, 'f', 3));
    painter.drawText(QPoint(x, y + 45), QString("%1 / %2 / %3").arg(m_xSize, 0, 'f', 3).arg(m_ySize, 0, 'f', 3).arg(m_zSize, 0, 'f', 3));

    QFontMetrics fm(painter.font());

    painter.drawText(QPoint(x, fm.height() + 10), m_parserStatus);
    painter.drawText(QPoint(x, fm.height() * 2 + 10), m_speedState);
    painter.drawText(QPoint(x, fm.height() * 3 + 10), m_pinState);

    QString str = QString(tr("Vertices: %1")).arg(vertices);
    painter.drawText(QPoint(this->width() - fm.width(str) - 10, y + 30), str);
    str = QString("FPS: %1").arg(m_fps);
    painter.drawText(QPoint(this->width() - fm.width(str) - 10, y + 45), str);

    str = m_spendTime.toString("hh:mm:ss") + " / " + m_estimatedTime.toString("hh:mm:ss");
    painter.drawText(QPoint(this->width() - fm.width(str) - 10, y), str);

    str = m_bufferState;
    painter.drawText(QPoint(this->width() - fm.width(str) - 10, y + 15), str);

    m_frames++;

#ifdef GLES
    update();
#endif
}

 数据更新与图形绘制

    // Update geometries in current opengl context
        foreach (ShaderDrawable *drawable, m_shaderDrawables)
            if (drawable->needsUpdateGeometry()) drawable->updateGeometry(m_shaderProgram);

        // Draw geometries
        foreach (ShaderDrawable *drawable, m_shaderDrawables) {
            drawable->draw(m_shaderProgram);
            if (drawable->visible()) vertices += drawable->getVertexCount();
        }

 

 

 

你可能感兴趣的:(3DPRINT,grbl)