app crashes when binding buffers and call draw function
void Graphics::make_buffer(GLenum object, GLenum type)
{
int offset = object * numperobj;
glGenBuffers(1, buf.buffer);
glBindBuffer(GL_ARRAY_BUFFER, buf.buffer[Vertices+ offset]);
glBufferData(GL_ARRAY_BUFFER, sizeof(floorverts), floorverts, GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
glEnableClientState(GL_VERTEX_ARRAY);
glGenBuffers(1, buf.buffer);
glBindBuffer(GL_ARRAY_BUFFER, buf.buffer[Colors + offset]);
glBufferData(GL_ARRAY_BUFFER, sizeof(floorcol), floorcol, GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
glEnableClientState(GL_COLOR_ARRAY);
glGenBuffers(1, buf.buffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf.buffer[Elements + offset]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(floorinds), floorinds, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
buf.PrimType[object] = type;
buf.NumElems[object] = sizeof(floorinds);
}
void Graphics::render(GLuint object)
{
int offset = object * numperobj;
glBindBuffer(GL_ARRAY_BUFFER, buf.buffer[Vertices + offset]);
glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, buf.buffer[Colors + offset]);
glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
glEnableClientState(GL_COLOR_ARRAY);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf.buffer[Elements + offset]);
glDrawElements(buf.PrimType[object], buf.NumElems[object], GL_UNSIGNED_INT, BUFFER_OFFSET(0));
}
And are you remembering to call glewInit? And doing so after you create your window and GL context? And on hardware that supports buffer objects?
Sorry if this offends you, but it's crashing because there is hardly one line of code there that isn't an error.
I'll add a full reply once I get back to my computer if nobody answers by then.
..snip..
glGenBuffers(1, buf.buffer); // You allocate a single buffer here.
glBindBuffer(GL_ARRAY_BUFFER, buf.buffer[Vertices+ offset]); // And then access it like an array here.
..snip..
}
If "buf.buffers" is an array, then you need to tell glGenBuffers how many buffers to generate. You are currently telling it to create one buffer, and then you access it like an array of buffers.
Also, you need a separate buffer for each array. One for "GL_VERTEX_ARRAY", one for "GL_COLOR_ARRAY" and one for "GL_ELEMENT_ARRAY". You are calling glGenBuffers three times in a row on the same buffer, thereby overwriting the buffer. At the end of your "make_buffer" function, only the element buffer exists.
Actually an "Access violation reading location 0x00000000" in the debugger most likely means a NULL function pointer, which is most likely that for glGenBuffers (the rest will also be NULL but glGenBuffers is just the first one hit), which means that either glewInit failed, or was called in the wrong order (which the OP has confirmed didn't happen) or the hardware doesn't support buffer objects.
It would have helped if the OP had stated which line the program crashed on too, but I'm going to make a guess despite that.
I see from e.g. http://forums.steampowered.com/forums/showthread.php?t=1733353 that the NVIDIA 330M is an Optimus card, so my betting is that this program is running on the Intel and that the Intel has an OEM driver with no OpenGL support.
The rest of the code, as pointed out by the other replies, also needs fixing.