I am trying to render terrain from a heightmap. I currently load the height map and can render it using vertex arrays with glBegin/glEnd but I need to do it with the use of VBOs. Since I'm using Qt the suggested method is QGLBuffer.
What am I doing wrong? vboV is a QGLBuffer which I initialize inside the initializeGL() function.
void GLWidget::initializeGL()
{
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
glClearColor(0,0,0,0);
vboV=new QGLBuffer(QGLBuffer::VertexBuffer);
vboV->create();
vboV->bind();
vboV->setUsagePattern(QGLBuffer::StaticDraw);
vboV->allocate(img->height()*img->width()*18);
vboV->release();
}
void GLWidget::paintGL()
{
//the commented section is using vertex array which works fine
// glEnableClientState(GL_VERTEX_ARRAY);
// glEnableClientState(GL_COLOR_ARRAY);
// glVertexPointer(3,GL_FLOAT,0,f);
// glColorPointer(3,GL_FLOAT,0,colorf);
// glDrawArrays(GL_TRIANGLES,0,img->height()*img->width()*6);
// glDisableClientState(GL_COLOR_ARRAY);
// glDisableClientState(GL_VERTEX_ARRAY);
vboV->bind();
glEnableClientState( GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,0,f);
glDrawArrays(GL_TRIANGLES,0,img->height()*img->width());
glDisableClientState(GL_VERTEX_ARRAY);
vboV->release();
}
I'm not sure what to change to make it work. The program runs, but the terrain does not render (it's just black).
f is an array of floats which contains {x1, y1, z1, x2, y2, z2...}; the positions of the vertices, which are set counter-clockwise. I don't know if the memory is allocated correctly, nor am I sure of glDrawArrays.
I'm using Qt 4.8.1 and my OS is Windows 7.
glBufferDataor similar. - radical7