i am just trying to render a simple triangle with the most basic OpenGL code, here it is: (all of these code are in the main() function)
GLfloat data[] = {
0, 0.5,
-0.5, -0.5,
0.5, -0.5
};
GLuint vertexBufferID;
glGenBuffers(1, &vertexBufferID);
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferID);
glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
while (!glfwWindowShouldClose(window))
{
glDrawArrays(GL_TRIANGLES, 0, 3);
}
if I do it this way, a triangle would appear on the screen, eveything works just fine, however the problem is that as soon as I move the buffer code(glGenBuffers, BindBuffer, BufferData etc) to another class, the triangle disappears, here is the code: (this is the main() function)
GLfloat data[] = {
0, 0.5,
-0.5, -0.5,
0.5, -0.5
};
//the buffer code is now called by this VertexBuffer constructor which
//requires vertex data to be passed into
VertexBuffer vertexBuffer(data);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
while (!glfwWindowShouldClose(window))
{
glDrawArrays(GL_TRIANGLES, 0, 3);
}
Here is the VertexBuffer class constructor code:
VertexBuffer::VertexBuffer(const void* data)
{
//the vertexBufferID here is defined in the header
glGenBuffers(1, &vertexBufferID);
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferID);
glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
}
So as I said the VertexBuffer constructor code is identical to the buffer code in the main() function before except it has been moved into another class. I am struggling to figure out what is the problem. Any help would be great, thank you.