Imgui: opengl3+glfw+glad it is error

Created on 25 Sep 2019  ·  3Comments  ·  Source: ocornut/imgui

I am Chinese,Maybe my English is a little bad. i am sorry
I've been tested.

target_link_libraries(ImguiTest PRIVATE gl3w)
#target_link_libraries(ImguiTest PRIVATE GLEW::GLEW)
#target_link_libraries(ImguiTest PRIVATE glad)

opengl3+glfw+gl3w and opengl3+glfw+glew are Perfect operation,
but opengl3+glfw+glad it is error, and it is show "Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)" and I don't understand
I debug it , it may be glBindSampler() , I Uncertain

backenbinding opengl

Most helpful comment

Hi, @bizehao.
You should be a little more specific... so it's hard to help you...

Anyway...
Usually this happens (with glad) when you call a function not present in the declared context profile:
e.g. if you declare a 3.0 GL/GLFW context and then you call a glBindSampler (it belong to OpenGL 3.2) you call a function whose "address / pointer" is not loaded (valid).

In this case (if the case is this) would be enough change the GLFW context initialization from:

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);

to

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);

below I add my initialization: it works with GLFW and GLAD

    glfwSetErrorCallback(glfwErrorCallback);

    if (!::glfwInit()) exit(EXIT_FAILURE);

// I use 4.5 context (or 4.1 on APPLE), but you can change it to 3.3 if need it
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
#ifdef APP_REQUIRE_OGL45
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
#else
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
#endif
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE);
    glfwWindowHint(GLFW_DOUBLEBUFFER, GL_TRUE);

    setGLFWWnd(glfwCreateWindow(GetWidth(), GetHeight(), getWindowTitle(), NULL, NULL));
    if (!getGLFWWnd())
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    glfwMakeContextCurrent(getGLFWWnd());

    //Init GLAD
    gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);

    glfwSetWindowSizeCallback(getGLFWWnd(), glfwWindowSizeCallback);

    glfwSwapInterval(1);

All 3 comments

Hi, @bizehao.
You should be a little more specific... so it's hard to help you...

Anyway...
Usually this happens (with glad) when you call a function not present in the declared context profile:
e.g. if you declare a 3.0 GL/GLFW context and then you call a glBindSampler (it belong to OpenGL 3.2) you call a function whose "address / pointer" is not loaded (valid).

In this case (if the case is this) would be enough change the GLFW context initialization from:

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);

to

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);

below I add my initialization: it works with GLFW and GLAD

    glfwSetErrorCallback(glfwErrorCallback);

    if (!::glfwInit()) exit(EXIT_FAILURE);

// I use 4.5 context (or 4.1 on APPLE), but you can change it to 3.3 if need it
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
#ifdef APP_REQUIRE_OGL45
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
#else
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
#endif
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE);
    glfwWindowHint(GLFW_DOUBLEBUFFER, GL_TRUE);

    setGLFWWnd(glfwCreateWindow(GetWidth(), GetHeight(), getWindowTitle(), NULL, NULL));
    if (!getGLFWWnd())
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    glfwMakeContextCurrent(getGLFWWnd());

    //Init GLAD
    gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);

    glfwSetWindowSizeCallback(getGLFWWnd(), glfwWindowSizeCallback);

    glfwSwapInterval(1);

thank you
I'll try your solution later.
I was going to build a cross-platform system, but there will be a lack of DLL running on Win10. So for the time being, I use directx12 on Windows and the combination of OpenGL + glfw + glew on linux. Thank you very much.

@BrutPitt Change the version of the statement by using your method glad. it is success, Thank you.

Was this page helpful?
0 / 5 - 0 ratings