Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Qt5 QOpenGL没有画任何东西_C++_Qt_Opengl_Qt5 - Fatal编程技术网

C++ Qt5 QOpenGL没有画任何东西

C++ Qt5 QOpenGL没有画任何东西,c++,qt,opengl,qt5,C++,Qt,Opengl,Qt5,我正在使用一个继承QGLWidget的小部件在我的Qt应用程序中显示OpenGL视口。 这个小部件只不过是创建三个CrenderVector并一直绘制它们而已 CRenderVector只是一组QVector3D、一个QOpenGLVertexArrayObject和三个QOpenGLBuffers,用于顶点、索引和颜色 顶点缓冲区对象是使用 const GLFloat color[] = {1, 0, 0, 1, 0, 0}; color_buffer.create(); color_buff

我正在使用一个继承QGLWidget的小部件在我的Qt应用程序中显示OpenGL视口。 这个小部件只不过是创建三个CrenderVector并一直绘制它们而已

CRenderVector只是一组QVector3D、一个QOpenGLVertexArrayObject和三个QOpenGLBuffers,用于顶点、索引和颜色

顶点缓冲区对象是使用

const GLFloat color[] = {1, 0, 0, 1, 0, 0};
color_buffer.create();
color_buffer.setUsagePattern(QOpenGLBuffer::StaticDraw);
color_buffer.bind();
color_buffer.allocate(color, sizeof(color);
color_buffer.release();
分别使用0、0、0和vec.{x、y、z}作为顶点缓冲区

顶点数组对象通过以下方式创建:

vertex_array.create();
vertex_array.bind();
    vertex_buffer.bind();
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_TRUE, 0, (void*)0);

    index_buffer.bind();

    color_buffer.bind();
    glEnableVertexAttribArray(1);
    glVertexAttribPointer(1, 3, GL_FLOAT, GL_TRUE, 0, (void*)0);
vertex_array.release();
绘制一个向量看起来像

vertex_array.bind();
glDrawElements(GL_LINES, elements, GL_UNSIGNED_INT, (void*)0);
vertex_array.release();
问题是,我在视口中看不到任何东西,除了清除的颜色,尽管我认为我正在使用如图所示的一切。我在哪里误解了Qt或OpenGL文档


QtCreator的剥离项目可在以下位置下载。

索引缓冲区a在构造函数中定义为元素数组吗?顶点缓冲区和颜色缓冲区是QOpenGLBuffer::顶点缓冲区,索引缓冲区是QOpenGLBuffer::IndexBuffer@Uroc327要查看某些内容,最简单的更改是将调用移动到view_projection.perspective在modelview之前向上绘制线集透视图。并将其更改为view_projection.perspective45,ratio,0.01,10;负的近似值对于透视投影来说毫无意义,它们只适用于正交投影projection@PeterT成功了。谢谢@彼得把它作为答案加上。