I am in the process of making a small game-engine for educational purposes, and I have come accross a very fustrating error. When debugging the program with the c++ gdb debugger an error occurs on the glGenVertexArrays(0, &m_vertexArrayObject);
- line 21 in the implementation of the addVertices
method, line in the second code extract. I searched for possible reasons and solutions on the internet and the answer I got was that I was making a mistake with pointers or uninitialized variables.
The debugger gives a
What am I doing wrong? I can post the full source on google drive and supply a link if needed.
//The call to the function giving the error:
Core::Core( int w, int h, std::string& title ):
running(false), width(w), height(h), m_title(title), game()
{
this->m_window = new Window(800, 600, "GameEngineCore");
RenderUtil::initGraphics();
mesh = new Mesh(); //the mesh class pointer is stored as a private class variable
mesh->addVertices(data, 3);
}
//The actual function causing the error:
void Mesh::addVertices(Vertex* vertices, unsigned int numVerts){
m_size = numVerts; // * Vertex::SIZE;
glGenVertexArrays(0, &m_vertexArrayObject); //error occurs here
glBindVertexArray(m_vertexArrayObject);
//place and bind vertices onto gpu memory
glGenBuffers(NUM_BUFFERS, m_vertexArrayBuffers);
glBindBuffer(GL_ARRAY_BUFFER, m_vertexArrayBuffers[POSITION_VB]);
glBufferData(GL_ARRAY_BUFFER, numVerts*sizeof(vertices[0]), &vertices[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(0); //divides data into attributes //only 1 attribute
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindVertexArray(0);
}
//constructor of the Mesh class
Mesh::Mesh()
:m_size(0)
{
}
//private variables of the Mesh class
enum{ NUM_BUFFERS, POSITION_VB, TEXCOORD_VB };
GLuint m_vertexArrayObject; //vertex array object - reference to mesh data
GLuint m_vertexArrayBuffers[NUM_BUFFERS]; //array of vertex array objects
unsigned int m_size;