Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. USE opengl load stl file problem(qml)
Forum Updated to NodeBB v4.3 + New Features

USE opengl load stl file problem(qml)

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 249 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.
  • lightwindL Offline
    lightwindL Offline
    lightwind
    wrote on last edited by
    #1

    Hello! I'm trying to load stl file by qtquick & opengl.
    Now I can load a triangle. But how can I load complete .stl file by this framework?
    I have tried add more points in vertices. Changed the setAttributeBuffer() function's value. But I still can't get more triangles.

    void TriangleRender::initializeTriangle()
    {
        VertexData vertices[] =
        {
            { QVector3D(-0.5f, -0.5f, 0.0f), QVector3D(1.0, 0.0, 0.0) },
            { QVector3D(0.0f, 0.5f, 0.0f),   QVector3D(0.0, 1.0, 0.0) },
            { QVector3D(0.5f, -0.5f, 0.0f),  QVector3D(0.0, 0.0, 1.0) }
        };
    
        m_vbo.create();
    
        m_vbo.bind();
        m_vbo.allocate(vertices, 3 * sizeof (VertexData));
    }
    
    void TriangleRender::render()
    {
        static float angle = 0.0;
    
        glClearColor(0.2, 0.3, 0.3, 1.0);
        glClear(GL_COLOR_BUFFER_BIT);
    
        angle += 1.0f;
        QMatrix4x4 modelMatrix;
        modelMatrix.translate(0.0, 0.0, -5.0);
        modelMatrix.rotate(angle, 0.0f, 1.0f, 0.0f);
    
        m_program.bind();
        m_program.setUniformValue("mvp",  m_projection * modelMatrix);
    
        m_vbo.bind();
    
    #ifdef Q_OS_WIN
        int location = 0;
        //position
        m_program.enableAttributeArray(location);
        m_program.setAttributeBuffer(location, GL_FLOAT, 0, 3, sizeof(VertexData));
        //color
        m_program.enableAttributeArray(location + 1);
        m_program.setAttributeBuffer(location + 1, GL_FLOAT, sizeof(QVector3D), 3, sizeof(VertexData));
    
    #else
        int vertexLocation = m_program.attributeLocation("position");
        m_program.enableAttributeArray(vertexLocation);
        m_program.setAttributeBuffer(vertexLocation, GL_FLOAT, 0, 3, sizeof(VertexData));
    
        int colorLocation = m_program.attributeLocation("color0");
        m_program.enableAttributeArray(colorLocation);
        m_program.setAttributeBuffer(colorLocation, GL_FLOAT, sizeof(QVector3D), 3, sizeof(VertexData));
    #endif
    
        glDrawArrays(GL_TRIANGLES, 0, 3);
    }
    

    GLSL:

    #version 330 core
    
    layout (location = 0) in vec4 position;
    layout (location = 1) in vec3 color0;
    
    out vec3 color;
    uniform mat4 mvp;
    
    void main(void)
    {
        gl_Position = mvp * position;
        color = color0;
    }
    
    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