Question

I have this code for an OpenGL project i'm doing and it draws nothing:

glBindBuffer(GL_ARRAY_BUFFER, g_terrainVBO);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3,        GL_FLOAT, GL_FALSE, 0, 0);

// Bind the buffers
glBindBuffer(GL_ARRAY_BUFFER, g_cubeVBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_cubeIBO);

// Draw the elements on the GPU
glDrawElements(
        GL_TRIANGLES,
        3*12,
        GL_UNSIGNED_INT,
        0); // SIZE IN BYTES, REMEMBER!

// Disable the vertex attributes (not necessary but recommended)
glDisableVertexAttribArray(0);

But when i remove the line

glBindBuffer(GL_ARRAY_BUFFER, g_terrainVBO);

the cube model is rendered perfectly. Now the g_terrainVBO do exist as i checked its size in the buffer using

// verify buffer size
int nBufferSize = 0;
glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &nBufferSize);
int originalVertexArraySize = ( nBufferSize / sizeof(TerrainModel::Vertex) );
cout << "Buffer size: " << originalVertexArraySize << endl;

and the size shows up correctly.

ANyone know what is the problem here? What is causing my terrain model VBO to bug the rendering and nothing shows (not even the cube)?

Was it helpful?

Solution

What did you expect to happen here?

If you setup the pointer relative to the terrain, then it is going to draw the terrain. glBindBuffer(GL_ARRAY_BUFFER, g_cubeVBO); does nothing in this code.

However, assuming this is your only drawing code, then if you remove glBindBuffer(GL_ARRAY_BUFFER, g_terrainVBO);, the next time you draw it is going to use g_cubeVBO (since the pointer uses whatever is bound to GL_ARRAY_BUFFER at the time it is called).

Rendering the terrain using the indices from the cube does not make much sense either.

Add this after you bind your cube VBO to restore some sanity to the world:

glVertexAttribPointer (0, 3, GL_FLOAT, GL_FALSE, 0, 0);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top