so I've been trying to create a simpler way to draw polygons and and have come across the following issue:
When I call glBindVertexArray(m_VAO);
it throws a GL_INVALID_OPERATION
even though I have previously called these functions:
glGenVertexArrays(1, &m_VAO);
glBindVertexArray(m_VAO);
Why does this happen? The only description for this error officially is that I failed to call the lines above.
Here is the source with any relevant parts. Please note that I have the error pop up the line after this one, but it might be because of this current error.
Polygon::Polygon(const std::vector<GLfloat>& vertexArray,
const char* vertShaderPath,
const char* fragShaderPath)
:m_vertexArray(vertexArray)
{
// Created and linked shaders here...
// ...
// ...
// Generate and bind vertex array object.
glGenVertexArrays(1, &m_VAO);
glBindVertexArray(m_VAO);
// Generate and bind vertex buffer object.
glGenBuffers(1, &m_VBO);
glBindBuffer(GL_ARRAY_BUFFER, m_VBO);
//Send verticies to buffer's memory.
glBufferData(GL_ARRAY_BUFFER,
m_vertexArray.size() * sizeof(GLfloat),
&m_vertexArray[0],
GL_STATIC_DRAW);
// Set up vertex attributes.
glVertexAttribPointer(0,
3,
GL_FLOAT,
GL_FALSE,
3 * sizeof(GLfloat),
(GLvoid*)0);
// Enable the attributes at layout position 0.
glEnableVertexAttribArray(0);
//Unbind VBO and VAO.
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
};
// Destructor
Polygon::~Polygon()
{
// De-allocated resources
glDeleteVertexArrays(1, &m_VAO);
glDeleteBuffers(1, &m_VBO);
}
void Polygon::draw()
{
glUseProgram(m_shaderProgram);
check_gl_error();
glBindVertexArray(m_VAO); // GL_INVALID_OPERATION here
check_gl_error();
glDrawArrays(GL_TRIANGLES, 0, m_vertexArray.size()); // GL_INVALID_OPERATION here
check_gl_error();
glBindVertexArray(0);
check_gl_error();
}
Let me know if you need any more info. Thanks!
check_gl_error();
after I create/bind it. Yes, my context is 3+(3.3). I get my functions with#include <GL/glew.h>
. Thanks \$\endgroup\$