1

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);
5
  • 5
    It has to be glGenBuffers(1, &vbo) rather than glGenVertexArrays(1, &vbo) Commented Jan 26, 2020 at 18:50
  • oh I know nothing about this "core profile context" thing. Thanks for pointing this to me, I'll investigate :) Commented Jan 26, 2020 at 18:53
  • 3
    @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. Commented Jan 26, 2020 at 19:12
  • 1
    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. Commented Jan 27, 2020 at 3:25
  • @Rabbid76 Why did you delete your answer? Commented Jan 27, 2020 at 8:54

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks I understand much better now what happened. I'll make sure to specify context in order to have a correct profile on any platform.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.