Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: VBO not rendering

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2011
    Posts
    13

    Exclamation 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:

    Code :
    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:


    Code :
        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:

    Code :
        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 );

  2. #2
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    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.
    Last edited by Nowhere-01; 05-02-2013 at 08:31 AM.

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2011
    Posts
    13
    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
    Last edited by Registrar; 05-02-2013 at 08:11 AM.

  4. #4
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    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.
    Last edited by Nowhere-01; 05-02-2013 at 08:43 AM.

  5. #5
    Junior Member Newbie
    Join Date
    Feb 2011
    Posts
    13
    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.

  6. #6
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    ok, i lagged a bit. it has 24 vertices to have proper texture coords and normals. my fault.

  7. #7
    Junior Member Newbie
    Join Date
    Feb 2011
    Posts
    13
    Okay, no problem. I really can't think of why the model is not showing up. Am I doing the perspective calculation right?

  8. #8
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    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.

  9. #9
    Junior Member Newbie
    Join Date
    Feb 2011
    Posts
    13
    What initial states could be interfering with the drawing?

  10. #10
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    i meant, probably you have some opengl initialization code, which fiddles with states.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •