Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED]Vertex Buffer Object error  (Read 2317 times)

0 Members and 1 Guest are viewing this topic.

sknnywhiteman

  • Newbie
  • *
  • Posts: 38
    • View Profile
    • Email
[SOLVED]Vertex Buffer Object error
« on: February 18, 2013, 12:06:44 am »
so.. I have NO idea why this is throwing an exception, but it's crashing my game whenever I call glDrawArrays. I set everything up correctly, and I've even copied-pasted code from tutorials that show people how to use VBOs, and it goes up to the glDrawArrays, and then crashes. I'm using sf::Renderwindow, and I get the error 0xC0000005: Access violation reading location 0x00000000.
GLuint createVBO(GLfloat* vertices, int size){
        GLuint vbo;
        glGenBuffers(1, &vbo);
        glBindBuffer(GL_ARRAY_BUFFER, vbo);
        glBufferData(GL_ARRAY_BUFFER, size*sizeof(GL_FLOAT), vertices, GL_STATIC_DRAW);
        glBindBuffer(GL_ARRAY_BUFFER, 0);
        return vbo;
}

//init function
glewInit();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, window.getSize().x, window.getSize().y, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_ALPHA_TEST);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
glLoadIdentity();
glAlphaFunc(GL_GREATER, 0.2f);
glLoadIdentity();
GLfloat *verts = new GLfloat[6];
verts[0] = 100.0f; //Verts at (100, 100), (200, 100), (150, 150)
verts[1] = 100.0f;
verts[2] = 200.0f;
verts[3] = 100.0f;
verts[4] = 150.0f;
verts[5] = 150.0f;
GLuint VertexVBOID = createVBO(verts, 6);
while(running){
        glBindBuffer(GL_ARRAY_BUFFER, VertexVBOID);
        glEnableClientState( GL_VERTEX_ARRAY );
        glVertexPointer(2, GL_FLOAT, 0, BUFFER_OFFSET(0));
        glDrawArrays(GL_TRIANGLES, 0, 3);
        glBindBuffer( GL_ARRAY_BUFFER, 0 );
        glDisableClientState( GL_VERTEX_ARRAY );
        window.display();
        sf::sleep(sf::milliseconds(16));
}

For anyone who is looking for the answer in the future, my problem was solved from http://www.sfml-dev.org/old-forum/viewtopic.php?t=7327&sid=c277620601084e8aa0f406a415a6b795. I hadn't disabled some states that SFML had enabled in secrecy. GL_TEXTURE_COORD_ARRAY & GL_COLOR_ARRAY.
« Last Edit: February 18, 2013, 02:42:54 am by sknnywhiteman »