I'm learning OpenGL and along with it, I'm creating classes and functions to reduce the amount of repeated code. At the moment, I'm creating a function around glBufferData and I'm not understanding what I'm doing wrong. When I build my code without calling my function, my box renders perfectly, but if I try my function, it doesn't render at all, and I only get my background color.
Here would be the relevant code. The rest of my code that creates vertex buffers, reads in shaders, etc... all work fine, I have tested all of that. The issue is when I wrap this specific function.
float vertices[] = {
0.5f, 0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
-0.5f, -0.5f, 0.0f,
-0.5f, 0.5f, 0.0f
};
unsigned int VAO, EBO;
VertexBuffer vb;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &EBO);
glBindVertexArray(VAO);
vb.Bind();
vb.LoadData(vertices); //this does not work
//This one below works when it's uncommented and the top is commented out
//glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
Function Definition of LoadData:
void VertexBuffer::LoadData(void* data)
{
glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
}
As mentioned before, I'm slowly creating wrapper classes and such, so far I create the VertexBuffer which calls glGenBuffers in the constructor. I then bind it and then try to call LoadData which takes in a void* because that's what the gl function is expecting as a 3rd parameter. I'm just not sure what I'd doing wrong. I have tried passing in my vertices by address, my simply writing the variable, making it const after realizing that the gl function expects a const but none of this has worked so far.
Any suggestions are much appreciated