1
votes

After switching from SFML to GLFW for window management, trying to bind my vbo leads to OpenGL error GL_INVALID_OPERATION (1282) with detail "Buffer name does not refer to an buffer object generated by OpenGL".

I manually checked my vbo and it seems to be assign a correct value.

Here is the working example I can produce, using glew-2.1.0 and glfw-3.3.0.


    if (!glfwInit())
    {
        return EXIT_FAILURE;
    }
    std::cout << glfwGetVersionString() << std::endl;
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
    glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
    auto window = glfwCreateWindow(g_width, g_height, "An Other Engine", nullptr, nullptr);
    if (window == nullptr)
    {
        return EXIT_FAILURE;
    }
    glfwMakeContextCurrent(window);
    if (glewInit() != GLEW_OK)
    {
        return EXIT_FAILURE;
    }
    GLint flags;
    glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
    if (flags & GL_CONTEXT_FLAG_DEBUG_BIT)
    {
        glEnable(GL_DEBUG_OUTPUT);
        glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
        glDebugMessageCallback(glDebugOutput, nullptr);
        glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE);
    }

    GLuint vao;
    glGenVertexArrays(1, &vao);
    glBindVertexArray(vao);
    GLuint vbo;
    glGenVertexArrays(1, &vbo);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
1
oh I know nothing about this "core profile context" thing. Thanks for pointing this to me, I'll investigate :) - Victor Drouin
@VictorDrouin: "I know nothing about this "core profile context" thing" It's not about core/compatibility. It's just a copy-and-paste error. You put glGenVertexArrays where you meant to say glGenBuffers. - Nicol Bolas
I swear it's not, code was perfectly functional using SFML. My answer was about Rabbid76's one that he deleted where he pointed me out this "core profile context" thing. I have yet to understand why but apparently contexts created with SFML didn't care. - Victor Drouin
@Rabbid76 Why did you delete your answer? - user253751

1 Answers

3
votes

In a core profile OpenGL Context, the buffer object (name) value has to be generated (reserved) by glGenBuffers. This is not necessary in a compatibility profile context.

You wrongly tried to generate the buffer name by glGenVertexArrays rather than glGenBuffers.

glGenVertexArrays(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);

That causes an INVALID_OPERATION error when you try to generate the buffer object by glBindBuffer.

Use glGenBuffers to solve the issue:

glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);

Note, you do not specify the profile type (glfwWindowHint(GLFW_OPENGL_PROFILE, ...)), by default the profile type is GLFW_OPENGL_ANY_PROFILE and not specified.