2016-07-26 138 views
1

我想使用glMapBuffer與QOpenGLWidget,但我找不到它。這裏是我的包含文件:OpenGL:如何在Qt中使用glMapBuffer?

#include <QOpenGLWidget> 
#include <QOpenGLFunctions> 
#include <QOpenGLBuffer> 
#include <QDebug> 
#include <QOpenGLTexture> 
#include <GL/gl.h> 
#include <GL/glext.h> 
#include <QGLFunctions> 
#include <QOpenGLShader> 
#include <QOpenGLShaderProgram> 

回答

0

你不應該混合QOpenGL和QGL(刪除你的項目配置QGLFunctions等老了,過時的OpenGL模塊)。你不需要包含gl.h和glext.h。

您包含QOpenGLBuffer。該方法map()封裝glMapBuffer:

// creation 

QOpenGLBuffer buffer = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer); 
buffer->create(); 

// allocation 

buffer->bind(); 

buffer->allocate(size_of_the_buffer); 

buffer->release(); 

// update 

buffer->bind(); 

void* buffer_data = buffer->map(QOpenGLBuffer::WriteOnly); 

memcpy(buffer_data, your_data_to_copy, size_of_your_data_to_copy); 

buffer->unmap(); 

buffer->release(); 
+0

地圖()方法工作QOpenGLBuffer對象,但我使用glBuffer我駐國際中心組織。我需要改變它,我不知道該怎麼做。 – Megatron300

+0

VBO是一個像其他OpenGL緩衝區:使用QOpenGLBuffer來管理它。我用一個例子編輯我的答案 – wasthishelpful

+0

好吧,用你的例子更好,但我仍然有問題。你的例子中的glBufferSubData等價於什麼?第一次數據傳輸時是否需要更新?它將如何與glVertexAttribPointer一起工作?我如何操作偏移量,因爲我在我的緩衝區中傳遞了Vertex和Texture coordonates數據。 – Megatron300