VBO not rendering

I’m on Windows 7 and using VC++ 2010.

I’m trying to load and render a mesh using VBOs. I’ve checked that all the indices and vertex values are valid, and I don’t get any crashes or errors from OpenGL.
Nothing is showing up on the screen…

In this model there are 36 indices and 24 verticies, just a simple cube.

vbo and indexVbo are both valid values. (vbo = 1, indexVbo = 2)

I’m checking glGetError in a loop untill it returns GL_NO_ERROR at the end of each frame and it always returns GL_NO_ERROR.

If you need any more information just ask.

(I have a valid window/opengl context/dc)

my vertex_t structure looks like this:


typedef struct
{
	float	location[3];	// 0
	float	st[3];			// 12
	float	normal[3];		// 24
	float	color[4];		// 36
} vertex_t;

this is how I load it:

    glGenBuffers( 1, &vbo );
    glBindBuffer( GL_ARRAY_BUFFER, vbo );


    glBufferData( GL_ARRAY_BUFFER, sizeof( vertex_t ) * numVerts, NULL, GL_STATIC_DRAW );
    glBufferSubData( GL_ARRAY_BUFFER, 0, sizeof( vertex_t ) * numVerts, vertList );


    glTexCoordPointer( 3, GL_FLOAT, sizeof( vertex_t ), 12 );
    glNormalPointer( GL_FLOAT, sizeof( vertex_t ), 24 );
    glColorPointer( 4, GL_FLOAT, sizeof( vertex_t ), 36 );
    glVertexPointer( 3, GL_FLOAT, sizeof( vertex_t ), 0 );


    glGenBuffers( 1, &indexVbo );
    glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, indexVbo );
    glBufferData( GL_ELEMENT_ARRAY_BUFFER, numIndices * sizeof( byte ), indexList, GL_STATIC_DRAW );

this is how I render it:

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );


    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective( 45.0, (double)1024 / (double)768, 5.0, 9999.0 );
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();


    glTranslatef( 0.0f, 0.0f, -25.0f );


    glBindBuffer( GL_ARRAY_BUFFER, vbo );
    glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, indexVbo );


    glEnableClientState( GL_TEXTURE_COORD_ARRAY );
    glEnableClientState( GL_COLOR_ARRAY );
    glEnableClientState( GL_NORMAL_ARRAY );
    glEnableClientState( GL_VERTEX_ARRAY );


    glTexCoordPointer( 3, GL_FLOAT, sizeof( vertex_t ), 12 );
    glNormalPointer( GL_FLOAT, sizeof( vertex_t ), 24 );
    glColorPointer( 4, GL_FLOAT, sizeof( vertex_t ), 36 );
    glVertexPointer( 3, GL_FLOAT, sizeof( vertex_t ), 0 );


    glDrawElements( GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, NULL );


    glDisableClientState( GL_TEXTURE_COORD_ARRAY );
    glDisableClientState( GL_COLOR_ARRAY );
    glDisableClientState( GL_NORMAL_ARRAY );
    glDisableClientState( GL_VERTEX_ARRAY );


    SwapBuffers( hdc );

don’t use bytes for indices. it certainly doesn’t work with at least some AMD drivers(i didn’t test it with 13.4, but with 13.1 it didn’t work). use GLuint’s.

The value of numVerts is 24. I changed the code to use GLuint instead of byte and it still doesn’t show up.

The value of numIndices is 36. The values of the verts are:

-1.000000 1.000000 1.000000
-1.000000 -1.000000 1.000000
1.000000 -1.000000 1.000000
1.000000 1.000000 1.000000
0.999999 -1.000001 -0.998797
-1.000000 -1.000000 -1.000000
-1.000000 1.000000 -1.000000
1.000000 0.999999 -1.000000
1.000000 -1.000000 1.000000
0.999999 -1.000001 -0.998797
1.000000 0.999999 -1.000000
1.000000 1.000000 1.000000
-1.000000 -1.000000 1.000000
-1.000000 -1.000000 -1.000000
0.999999 -1.000001 -0.998797
1.000000 -1.000000 1.000000
-1.000000 1.000000 1.000000
-1.000000 1.000000 -1.000000
-1.000000 -1.000000 -1.000000
-1.000000 -1.000000 1.000000
-1.000000 1.000000 -1.000000
-1.000000 1.000000 1.000000
1.000000 1.000000 1.000000
1.000000 0.999999 -1.000000

so with numVerts, you say that there are 24 vertex_t’s in vertex array. one vertex_t consists of 13 floats, according to your struct definition. so if that list contains only vertex positions, then where are other attributes? if you want to use vertex data in the way your code suggests - it should be all contained in that vertList array, like that: {position.xyz, tex_coord.str, normal.xyz, color.rgba} * numVerts.

and post your new code for unsigned int’s. it may contain mistakes.

Yeah it’s just the vertex positions. I have all the others in there as well. I’m using Asset Importer (http://assimp.sourceforge.net/) to load the model. I’m just counting the number of vertices it’s giving me and allocating an array of that side (numVerts). I’ll see what I can do in the library or in Blender to lower the number of vertices.

ok, i lagged a bit. it has 24 vertices to have proper texture coords and normals. my fault.

Okay, no problem. I really can’t think of why the model is not showing up. Am I doing the perspective calculation right?

the only suspicion i have currently is you didn’t fix data type and sizes for indices properly.or it has something to do with initial opengl states.

What initial states could be interfering with the drawing?

i meant, probably you have some opengl initialization code, which fiddles with states.

Fixed it! Turns out the vertex colors were all black, same as the clear color. Thanks for your help.