I am currently learning GFLW and OpenGL in C++, and I have come across a very weird error that I really can't figure out why it is occurring. I have two Vertex Buffers, one contains the data for a triangle, and the other contains data for a cube. When I create the Vertex Buffer for the Triangle and draw it without creating the Vertex Buffer for the Cube, it works perfectly and draws to the window the expected triangle. However, if I create the second Vertex Buffer and draw only the triangle again it becomes distorted.
Output when only the triangle Vertex Buffer is created:
Output when both the triangle Vertex Buffer and Cube Vertex Buffer are created (cube vertex buffer is never used)
Vertex Buffer's constructor
VertexBuffer(const GLvoid *data, GLsizeiptr size, GLenum mode, GLsizei count, GLsizei stride, ShaderInterface *shader, GLvoid *positionOffset, GLvoid *normalOffset);
Creating the two vertex buffers:
VertexBuffer *vertexBuffer=new VertexBuffer(vertices,sizeof(vertices),
GL_TRIANGLES,
3,
sizeof(GL_FLOAT)*3,
shaderArray->at(0),
NULL,
NULL);
vertexBufferArray->push_back(vertexBuffer);
VertexBuffer *cubeVertexBuffer=new VertexBuffer(cubeVertices,
sizeof(cubeVertices),
GL_TRIANGLES,
36,sizeof(VertexDataPN),
shaderArray->at(1),
(GLvoid*)(offsetof(VertexDataPN,positionCoordinates)),
(GLvoid*)(offsetof(VertexDataPN,normalCoordinates)));
//vertexBufferArray->push_back(cubeVertexBuffer);
And the contents of the constructor for my Vertex Buffer class:
glGenBuffers(1,&vertexBufferID);
glBindBuffer(GL_ARRAY_BUFFER,vertexBufferID);
glBufferData(GL_ARRAY_BUFFER,size,data,GL_STATIC_DRAW);
Also, I have already checked that the vertexBufferID's are different for both of them. The Cube Vertex Buffer is never used or referenced to after it gets created. If anyone knows why this is occurring please let me know.