Original Post
Hey All
I'm trying to write a wrapper for vertex buffer objects, I have this code:
#include <gl/GLee.h>
#include "OGLVertexBuffer.h"
OGLVertexBuffer::OGLVertexBuffer() : IVertexBuffer()
{
isLocked = false;
size = 0;
}
OGLVertexBuffer::~OGLVertexBuffer()
{
destroy();
}
bool OGLVertexBuffer::create(uint size)
{
this->size = size;
glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, size, 0, GL_STATIC_DRAW);
return true;
}
void OGLVertexBuffer::destroy()
{
glDeleteBuffers(1, &buffer);
}
void *OGLVertexBuffer::lock(int access)
{
void *v;
glBindBuffer(GL_ARRAY_BUFFER, buffer);
if (!isLocked) {
v = glMapBuffer(GL_ARRAY_BUFFER, access);
isLocked = true;
} else
glGetBufferPointerv(GL_ARRAY_BUFFER, GL_BUFFER_MAP_POINTER, &v);
return v;
}
bool OGLVertexBuffer::unlock()
{
glBindBuffer(GL_ARRAY_BUFFER, buffer);
if (glUnmapBuffer(GL_ARRAY_BUFFER)) {
isLocked = false;
return true;
}
return false;
}
void OGLVertexBuffer::draw(int first, int nrVerticies, VertexStrive strive)
{
if (strive == V3F_C4UB) {
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glInterleavedArrays(GL_C4UB_V3F, 0, &buffer);
glDrawArrays(GL_TRIANGLES, first, nrVerticies);
}
}
and then I use this class to render like this:
// My costum vertex
struct MyVertex {
GLubyte r, g, b, a;
float x, y, z;
};
// This is done once
MyVertex vertex[6] = {
{ 255, 0, 0, 255, -1.0f, 0.0f, 0.0f},
{ 0, 255, 0, 255, 1.0f, 0.0f, 0.0f},
{ 0, 0, 255, 255, 1.0f, 2.0f, 0.0f},
{ 0, 0, 255, 255, 1.0f, 2.0f, 0.0f},
{ 0, 255, 0, 255, -1.0f, 2.0f, 0.0f},
{ 255, 0, 0, 255, -1.0f, 0.0f, 0.0f}
};
vb = new OGLVertexBuffer();
vb->create(6*sizeof(MyVertex));
void *v = vb->lock(GL_WRITE_ONLY);
memcpy(v, vertex, sizeof(MyVertex)*6);
vb->unlock();
// This is done every frame
vb->draw(0, 2, V3F_C4UB);
I am getting the error "The instruction at "0x08c7beff" referenced memory at "0x119df0ec". The memory could not be "read".
If I debug the code in VS it breaks in the draw method at the call to glDrawArrays(...).
LizardCPP
[edited by - LizardCPP on April 18, 2004 6:44:12 PM]