0

I have a bunny.h which contains the following data:

bunny[] | vertex coordinates xyz

NUM_TRIANGLES | the amount of triangles for the bunny

normals[] | the normals for each triangle

triangles[] | indices for the triangles

I want to use the data for a vertex buffer object.

here is how I try to load the data

GLfloat values[NUM_TRIANGLES*3];
    for(int i = 0; i < NUM_TRIANGLES*3; i++)
        values[i] = bunny[i];

  //  init and bind a VBO (vertex buffer object) //
    glGenBuffers(1, &bunnyVBO);
    glBindBuffer(GL_ARRAY_BUFFER, bunnyVBO);


  //  copy data into the VBO //
    glBufferData(GL_ARRAY_BUFFER, sizeof(values), &values, GL_STATIC_DRAW);

  // init and bind a IBO (index buffer object) //
    glGenBuffers(1, &bunnyIBO);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bunnyIBO);

  //  copy data into the IBO //
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(triangles), &triangles, GL_STATIC_DRAW);
  // unbind active buffers //
  glBindVertexArray(0);
  glBindBuffer(GL_ARRAY_BUFFER, 0);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

Later in the program I want to render the buffers using this code:

glBindBuffer(GL_ARRAY_BUFFER, bunnyVBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bunnyIBO);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawElements(GL_TRIANGLES, NUM_TRIANGLES, GL_UNSIGNED_INT, triangles);
glDisableClientState(GL_VERTEX_ARRAY);

OpenGL is working fine, but I dont see the bunny... (the data is not corrupted or anything like that, the error is in my code) Can some please help me?

Nightfirecat
  • 11,432
  • 6
  • 35
  • 51
glethien
  • 2,440
  • 2
  • 26
  • 36

1 Answers1

2

I don't see any call to glVertexPointer. And if you want to use the elements from the VBO, it should be

glDrawElements(GL_TRIANGLES, NUM_TRIANGLES, GL_UNSIGNED_INT, 0);
JWWalker
  • 22,385
  • 6
  • 55
  • 76
  • Where do I have to call glVertexPointer - Loading data or rendering data? – glethien Apr 16 '13 at 19:20
  • 1
    @glethien: During rendering. The pointer you pass to it is an offset within the vertex VBO, in this case zero. – JWWalker Apr 16 '13 at 19:27
  • I tried, but still black - Rendering inlcudes glVertexPointer before glDrawElements. – glethien Apr 16 '13 at 19:30
  • 2
    There are many possible reasons to get nothing but black in OpenGL, e.g., the geometry may be black, or you modelview or projection matrices may be wrong. There's not enough information to tell what's wrong. – JWWalker Apr 16 '13 at 19:40