This is my first time using OpenGL, so this may be a stupid question, but my code is pulling a GL_INVALID_OPERATION
error (1218
or 0x0502
) between glBegin()
and glEnd()
. I'm only calling a couple simple commands but glGetError()
returns 0
at the start of this function, and 1218
at the end.
This function is intended to be used to draw a single instance of any simple shape, and after stepping through in the debugger, the variables are what I intended them to be. Also note that, despite this being a stupid question, I spent several hours last night and several hours today searching Google and my textbook for possible solutions, and have found nothing helpful due to the vague nature of OpenGL errors.
void drawShape(GLenum type, int numPoints, GLubyte r, GLubyte g, GLubyte b, vertex vertices, ...) {
glBegin(type);
glColor3ub(r, g, b);
// iterate through vertices
va_list vertexList;
va_start(vertexList, vertices); // use vertexList for iteration
for (int i = 0; i < numPoints; ++i) {
vertex point = i == 0 ? vertices : va_arg(vertexList, vertex);
// add a new point at (x, y)
glVertex2i(std::get<0>(point), std::get<1>(point));
}
glEnd();
}
This function is called as follows:
drawShape(GL_LINE, 2, 0, 0, 0, vertex{ 10, 10 }, vertex{ 400, 10 });
And the context I'm using is FreeGLUT which is initialized as follows:
// gross workaround for calling init with no arguments
int argc = 1;
char *argv[1] = { (char*)"" };
glutInitContextVersion(4, 1);
glutInit(&argc, argv);
// RGB window, double buffer
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
// sets values necessary for window initialization
glutInitWindowPosition(INIT_X, INIT_Y);
glutInitWindowSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
// draw the window and create the scene
glutCreateWindow(WORKING_WINDOW_TITLE);
glClearColor(1, 1, 1, 1); // set clear color to white
glutDisplayFunc(render);
glutMainLoop();