wadesworld

09-15-2009, 09:55 PM

Anyone see any errors in this very simple test VBO code? It looks correct to me, but I'm not seeing any evidence of drawing. My immediate mode code does draw however.

struct vert3d_struct

{

GLfloat x;

GLfloat y;

GLfloat z;

};

typedef struct vert3d_struct vert3d;

vert3d *vertices;

GLushort *indices;

GLuint vboBuffers[2];

vertices[0].x = -20.0;

vertices[0].y = -20.0;

vertices[0].z = 0;

vertices[1].x = 20.0;

vertices[1].y = -20.0;

vertices[1].z = 0;

vertices[2].x = 20.0;

vertices[2].y = 20.0;

vertices[2].z = 0;

vertices[3].x = -20.0;

vertices[3].y = 20.0;

vertices[3].z = 0;

verticesCount = 4;

indices[0]=0;

indices[1]=1;

indices[2]=2;

indices[3]=3;

vertices = (vert3d *) malloc ( 4 * (sizeof(vert3d)));

indices = (GLushort *) malloc( 4 * sizeof(GLushort) );

glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboBuffers[0]); //vertex data

glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, vboBuffers[1]); //indicies

glBufferDataARB(GL_ARRAY_BUFFER_ARB, 4 * (sizeof(vert3d)), vertices, GL_STATIC_DRAW_ARB);

glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 4 * sizeof(GLushort), indices, GL_STATIC_DRAW_ARB);

glEnableClientState(GL_VERTEX_ARRAY);

glColor3f(0.0, 0.0, 1.0);

glDrawElements(GL_QUADS, verticesCount, GL_UNSIGNED_SHORT, 0);

glDisableClientState(GL_VERTEX_ARRAY);

Thanks for any thoughts.

struct vert3d_struct

{

GLfloat x;

GLfloat y;

GLfloat z;

};

typedef struct vert3d_struct vert3d;

vert3d *vertices;

GLushort *indices;

GLuint vboBuffers[2];

vertices[0].x = -20.0;

vertices[0].y = -20.0;

vertices[0].z = 0;

vertices[1].x = 20.0;

vertices[1].y = -20.0;

vertices[1].z = 0;

vertices[2].x = 20.0;

vertices[2].y = 20.0;

vertices[2].z = 0;

vertices[3].x = -20.0;

vertices[3].y = 20.0;

vertices[3].z = 0;

verticesCount = 4;

indices[0]=0;

indices[1]=1;

indices[2]=2;

indices[3]=3;

vertices = (vert3d *) malloc ( 4 * (sizeof(vert3d)));

indices = (GLushort *) malloc( 4 * sizeof(GLushort) );

glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboBuffers[0]); //vertex data

glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, vboBuffers[1]); //indicies

glBufferDataARB(GL_ARRAY_BUFFER_ARB, 4 * (sizeof(vert3d)), vertices, GL_STATIC_DRAW_ARB);

glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 4 * sizeof(GLushort), indices, GL_STATIC_DRAW_ARB);

glEnableClientState(GL_VERTEX_ARRAY);

glColor3f(0.0, 0.0, 1.0);

glDrawElements(GL_QUADS, verticesCount, GL_UNSIGNED_SHORT, 0);

glDisableClientState(GL_VERTEX_ARRAY);

Thanks for any thoughts.