Luciano Lorenti
Luciano Lorenti

Reputation: 601

QGLBuffer and VBO

I have a problem with QGLBuffer. I'm trying to implement a dynamic VBO with QT + Opengl.

In the .h file

struct CVert {
   float x;                                                 
   float y;                                                 
};
...

typedef struct CVert CVert;     
CVert* m_data;
QGLBuffer* m_bufferData;
int m_size;

in the .cpp

Constructor.

m_size = numberOfVertex;
m_bufferData = new QGLBuffer(QGLBuffer::VertexBuffer);
m_bufferData->create();
m_bufferData->bind();
m_bufferData->setUsagePattern(QGLBuffer::DynamicDraw);
m_bufferData->allocate(2*sizeof(float)* p_size);
m_data = (CVert*)m_bufferData->map (QGLBuffer::ReadWrite);

In the execution of the program I change some m_data values

m_data[pos].x = X1
m_data[pos].y = y1

In the draw method.

glEnableClientState(GL_VERTEX_ARRAY);
if (m_bufferData->bind ()) {
   glVertexPointer( 2, GL_FLOAT, 0, (char *) NULL );;
   glDrawArrays( GL_LINES, 0,m_size );
   glDisableClientState(GL_VERTEX_ARRAY);
}

But nothig it's being drawn. I've checked that m_data is not null, and m_bufferData->bind() returns true. What am I doing wrong?

Upvotes: 2

Views: 2564

Answers (1)

Luciano Lorenti
Luciano Lorenti

Reputation: 601

I think i've solved. Every time i've to edit the VBO. I have to

m_data = (CVert*)data->map (QGLBuffer::ReadWrite); 
m_data[pos].x = X1;
m_data[pos].y = y1 
data->unmap (); 

it's doesn't work if I map only once in the constructor

Upvotes: 2

Related Questions