C++ Qt 5.3 OpenGL-使用核心轮廓绘制顶点缓冲区对象
我使用Qt5.3创建了一个QWindow来做一些基本的渲染工作。QWindow声明如下:C++ Qt 5.3 OpenGL-使用核心轮廓绘制顶点缓冲区对象,c++,qt,opengl,compatibility,C++,Qt,Opengl,Compatibility,我使用Qt5.3创建了一个QWindow来做一些基本的渲染工作。QWindow声明如下: class OpenGLWindow : public QWindow, protected QOpenGLFunctions_3_3_Core { Q_OBJECT ... } 它在构造函数中初始化: OpenGLWindow::OpenGLWindow(QWindow *parent) : QWindow(parent) { QSurfaceFormat format
class OpenGLWindow : public QWindow, protected QOpenGLFunctions_3_3_Core
{
Q_OBJECT
...
}
它在构造函数中初始化:
OpenGLWindow::OpenGLWindow(QWindow *parent) : QWindow(parent)
{
QSurfaceFormat format;
format.setVersion(3,3);
format.setProfile(QSurfaceFormat::CoreProfile);
this->setSurfaceType(OpenGLSurface);
this->setFormat(format);
this->create();
_context = new QOpenGLContext;
_context->setFormat(format);
_context->create();
_context->makeCurrent(this);
this->initializeOpenGLFunctions();
...
}
这就是渲染代码:
void OpenGLWindow::render()
{
if(!isExposed())
return;
_context->makeCurrent(this);
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(_shaderProgram);
glBindBuffer(GL_ARRAY_BUFFER, _positionBufferObject);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
glUseProgram(0);
_context->swapBuffers(this);
}
我正在尝试使用顶点和片段着色器绘制一个简单的三角形。问题是,当设置岩心剖面时,三角形没有显示。只有当我将OpenGL版本设置为2.0或使用兼容性配置文件时,它才会显示出来。在我看来,这没有任何意义,因为我根本没有使用固定的功能。我遗漏了什么?在QGLWidget中使用PaintEvent或PaintGL执行相同操作时,结果如何?如果我没有记错,QGLWidget与新的Qt API for openGL无关。它使用QSurface和QWindow。你能在
\u context->makeCurrent(这个)之后检查一下吗代码>曲面和上下文的格式是否为3.3核心?我也有同样的问题。我手头没有家用电脑,所以我现在无法浏览我的历史记录,为您提供指向解决方案的链接。还可以看看这个:。你能检查你得到的函数指针是否不为空吗?上下文和曲面都是3.3内核,函数指针不为空。你需要创建并绑定一个顶点数组对象(VAO)。在核心配置文件中,不推荐使用不带VAO的顶点缓冲区。这已经出现过几次了,我稍后会尝试找到一个副本。你的意思是删除。在核心概要文件中,只有一些东西是不推荐的,比如宽线条。