GL_INVALID_ENUM right after context initialization
c++, opengl
Solution
Vertex array objects are not optional in the core profile. The `GL_INVALID_ENUM` error is probably coming from somewhere else; you should be getting `GL_INVALID_OPERATION`. Remember: OpenGL errors are buffered, so you have to keep fetching GL errors until you come back with `GL_NO_ERROR`.
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT,GL_TRUE);
Please stop doing this. Forward compatibility is virtually meaningless in a core profile.
Problem
I am getting GL_INVALID_ENUM code when calling glGetError right after glew init has finished and before any other gl command was called.I am setting OpenGL 4.2 CORE ,forward compatible.Using GLFW for window/input and GLEW for gl context all this running on Windows 7 64bit.My graphic card is GeForce 550GT which has the latest drivers with OpenGL 4.2.Another strange thing is that I was using glDrawElements() which worked fine.But then I tried glDrawArrays(), which I needed for some specific task, and it didn't work at all.I double rechecked all the gl syntax ,buffer creations shaders etc.Nothing.I do get GL_INVALID_OPERATION when calling glDrawArrays() and I have no Idea why.All this work is a mini render engine but currently the pipeline is really simple so I can't understand what can be the problem.Here is how I initialize the context and window: ``` void Engine::InitWithGLFW(){ if(!glfwInit()){ exit(EXIT_FAILURE); } glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT,GL_TRUE); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwOpenWindowHint(GLFW_FSAA_SAMPLES,0); glfwDisable( GLFW_AUTO_POLL_EVENTS ); #ifdef DEBUG glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); #endif if(!glfwOpenWindow(_width,_height,8, 8, 8, 8, 24, 8,GLFW_WINDOW)){ glfwTerminate(); exit(EXIT_FAILURE); } glfwSetWindowTitle("XDEngine V-1.0"); InitGlew(); } void Engine::InitGlew(){ glewExperimental=GL_TRUE; GLenum err = glewInit(); if (GLEW_OK != err) { /* Problem: glewInit failed, something is seriously wrong. */ fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); } fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); glEnable(GL_MULTISAMPLE); glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_DEPTH_TEST); glDepthMask(true); glDepthFunc(GL_LEQUAL); glDepthRange(0.0f, 1.0f); glEnable(GL_DEPTH_CLAMP); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glfwSetWindowSizeCallback(Reshape); } ``` And this is the render loop for glDrawArrays(): ``` void Draw(){ _material->Draw();///activate shader program glBindBuffer(GL_ARRAY_BUFFER, vbo); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0); glDrawArrays(GL_TRIANGLES, 0, 3); glDisableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); _material->PostDraw(); //deactivate shader program } ``` As I said , all the buffers and shader programs are initialized ok. UPDATE: Ok , I found the answer for the first issue : Seems like GL_INVALID_ENUM may happen after GlewInit and it is not supposed to screw the rendering.So I am left with the second problem... UPDATE1: I found the workaround for GL_INVALID_ENUM when calling glDrawArrays() with VBO.If I pack the VBO into VAO The error disappears and I get the rendering working.Does it mean that in forward compatible core profile we can't draw using VBO directly?Never seen anything related to it in the official docs.