VBO与OpenGL 4.1和3.0的兼容性

时间:2017-07-14 13:43:07

标签: c++ opengl vbo qglwidget qt5.8

我有一个显示一些3D渲染的应用程序。 当我将应用程序集成到不同用户的笔记本电脑上时,我遇到了VBO的一些图形问题。顶点缓冲区对象在开发站中完美运行

第一台笔记本电脑嵌入了AMD Radeon HD 6470M - > OpenGL 4.1

在这台笔记本电脑上,我有一些: 旧时尚方式opengl代码,工作正常。 vbo实现:没有显示VBO的数据

这里负责绘制我的VBO的代码:

    // Compute this on the client side to attempt compute it for each vertex
    Matrix4 modelview = view * model;

    // Links matrix values to entry shader matrices for the specified shader
    glUniformMatrix4fv(glGetUniformLocation(shaderID, "projection"), 1, GL_TRUE, projection.getValues());
    glUniformMatrix4fv(glGetUniformLocation(shaderID, "modelview"), 1, GL_TRUE, modelview.getValues());
    GLfloat color[4] = {material_->getDiffuse()[0], material_->getDiffuse()[1], material_->getDiffuse()[2], lgc3d::alphaFromSelection(selected)};
    glUniform4fv(glGetUniformLocation(shaderID, "color"), 1, color);


    // Get the positions in the shader for data
    glEnableVertexAttribArray(VPos_index);
    glEnableVertexAttribArray(VNor_index);
    glEnableVertexAttribArray(VTex_index);

    // Bind the buffers we want access
    glBindBuffer(GL_ARRAY_BUFFER, VBO_index_vertices);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, VBO_index_indices3);
    glBindTexture(GL_TEXTURE_2D, material_->getTexture().getID());
    {
        // Precise how the data have to be read by OpenGL (defining offset), for triangles
        glVertexAttribPointer(VPos_index, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(0));
        glVertexAttribPointer(VNor_index, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(offsetof(Vertex, normals)));
        glVertexAttribPointer(VTex_index, 2, GL_FLOAT, GL_TRUE, sizeof(Vertex), BUFFER_OFFSET(offsetof(Vertex, textcoords)));
        glDrawElements(GL_TRIANGLES, nb_tri_ * 3, GL_UNSIGNED_INT, 0);
    }

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, VBO_index_indices4);
    {
        // Precise how the data have to be read by OpenGL (defining offset), for quads
        glVertexAttribPointer(VPos_index, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(0));
        glVertexAttribPointer(VNor_index, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(offsetof(Vertex, normals)));
        glVertexAttribPointer(VTex_index, 2, GL_FLOAT, GL_TRUE, sizeof(Vertex), BUFFER_OFFSET(offsetof(Vertex, textcoords)));
        glDrawElements(GL_QUADS, nb_qua_ * 4, GL_UNSIGNED_INT, 0);
    }

    // Unbind everything
    glDisableVertexAttribArray(VPos_index);
    glDisableVertexAttribArray(VNor_index);
    glDisableVertexAttribArray(VTex_index);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    glBindTexture(GL_TEXTURE_2D, 0);

我是否使用过时的功能?我真的没有这种感觉。

非VBO对象完美显示:

    {
    // defines an array of generic vertex attribute data, of index 0
    glEnableVertexAttribArray(0);

        // Get eye position
        Vector3D eyev(cam->getEyePosition());
        float eyet[3] = {(float)eyev.X, (float)eyev.Y, (float)eyev.Z};

        // Specify data location for OpenGL
        glVertexAttribPointer(0, 3, GL_DOUBLE, GL_FALSE, 0, vertices_);

        // Links matrix values to entry shader matrices for the specified shader
        glUniformMatrix4fv(glGetUniformLocation(shaderID, "projection"), 1, GL_TRUE, projection.getValues());
        glUniformMatrix4fv(glGetUniformLocation(shaderID, "modelview"), 1, GL_TRUE, modelview.getValues());
        glUniform3fv(glGetUniformLocation(shaderID, "cameraEye"), 1, eyet);

        glLineWidth(1);

        // Order OpenGL to draw
        glDrawArrays(GL_LINES, 0, nb_coord_ / 3);

    // Inactivates the generic vertex attribute data of index 0
    glDisableVertexAttribArray(0);
}

第二台笔记本电脑嵌入了Intel Graphic 3000 - > OpenGL 3.0

在这里,如果我只将鼠标放在OpenGL canevas上,它就会崩溃。什么都不会显示......甚至背景清除颜色。

我注意不要使用已弃用的功能,我真的认为一切都可以兼容一大堆电脑/笔记本电脑。有没有人有任何想法?

所有内容都显示在QGLWidget中,Qt5.8。在Windows 7 Professional上测试的64位平台上出现问题。

0 个答案:

没有答案