VBO segfaulting [solved]

Started by
1 comment, last by J2902 14 years, 7 months ago
I'm trying to use a VBO, but it keeps on segfaulting on me. Here is how I set up the VBO

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

    GLfloat vertexData[] = {0.0f, 1.0f,
                          0.0f, 0.0f,
                          1.0f, 1.0f,
                          1.0f, 0.0f};

    GLfloat colorData[] = {.3f, .3f, .3f, 1.f,
                           .5f, .5f, .5f, 1.f,
                           1.f, .5f, .5f, 1.f,
                           1.f, 1.f, 1.f, 1.f};

    glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData) + sizeof(colorData), 0, GL_STATIC_DRAW);
    glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertexData), vertexData);
    glBufferSubData(GL_ARRAY_BUFFER, sizeof(vertexData), sizeof(colorData), colorData);

    glColorPointer(4, GL_FLOAT, 0, (void*)(sizeof(vertexData)));
    glVertexPointer(2, GL_FLOAT, 0, (void*)(0));

    glBindBuffer(GL_ARRAY_BUFFER, 0);


and here is how I render it.

glBindBuffer(GL_ARRAY_BUFFER, m_testVBO);
  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_COLOR_ARRAY);

  glColorPointer(4, GL_FLOAT, 0, (GLvoid*)(8 * sizeof(GLfloat)));
  glVertexPointer(2, GL_FLOAT, 0, 0);
  
  glDrawArrays(GL_QUADS, 0, 4);

  glDisableClientState(GL_COLOR_ARRAY);
  glDisableClientState(GL_VERTEX_ARRAY);

  glBindBuffer(GL_ARRAY_BUFFER, 0);


At this point, I have no idea what I'm doing wrong. (I'm just trying to render a rectangle.) [Edited by - J2902 on September 12, 2009 6:18:10 PM]
Advertisement
The code looks correct to me, so just make sure there are no GL errors, you have existing context while creating the VBO and m_testVBO is not zero.
/sigh I thought I had a valid context, but upon closer examination I didn't. :(

Thanks.

This topic is closed to new replies.

Advertisement