0

Hello it took me two days to figure out why my window always closed instand.

It was because i called gladLoadGL(glfwGetProcAddress) before glfwMakeContextCurrent(window).

This does NOT work:

int main() {
    glfwInit();

    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    gladLoadGL(glfwGetProcAddress);
    GLFWwindow * window = glfwCreateWindow(600, 600, "agag", NULL, NULL);
    glfwMakeContextCurrent(window);
    while (!glfwWindowShouldClose(window)) {
        glClear(GL_COLOR_BUFFER_BIT);
        glClearColor(0.2f, 0.5f, 0.6f, 1);
        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    glfwTerminate();
}

But when i call gladLoadGL(glfwGetProcAddress); AFTER glfwMakeContextCurrent(window); it DOES work!

Do i have load glad everytime i am switching the window? (maybe later i have to) But is it really like that or is it a bug?

When i write it before glfwMakeContextCurrent the error:

-1073741819 (0xC0000005)

comes up.

genpfault
  • 51,148
  • 11
  • 85
  • 139
CloudBeta
  • 1
  • 2
  • 2
    Do you know what GLAD does? – user253751 Nov 15 '22 at 15:11
  • Not really i heard it does something with the window creation but that does not make much sence now... – CloudBeta Nov 15 '22 at 15:16
  • why are you using something if you don't know what it does? was it a tutorial that said "use this because I said so"? – user253751 Nov 15 '22 at 15:16
  • I mean i watch the tutorial because i dont know what things do? Isnt that the sence of tutorials? – CloudBeta Nov 15 '22 at 15:18
  • yes but it's supposed to tell you what they do. (not all tutorials do what they're supposed to) – user253751 Nov 15 '22 at 15:19
  • In the learn glfw they said i have to use it to use modern methods but that doesnt explain why i have to call it after – CloudBeta Nov 15 '22 at 15:21
  • So do i always have to call the method after changing the ContextCurrent ? – CloudBeta Nov 15 '22 at 16:16
  • Similar question answered here: https://stackoverflow.com/questions/73669245/do-i-need-to-call-glewinit-for-every-glfw-window-i-create/73670331#73670331. But in short, only in Windows, you need a context to load the functions, because they are bound to the context. In Linux, you can load the functions whenever you want. – Erdal Küçük Nov 17 '22 at 10:04
  • @ErdalKüçük Note that the answer to which you provide a [link](https://stackoverflow.com/questions/73669245/do-i-need-to-call-glewinit-for-every-glfw-window-i-create/73670331#73670331) is about `Glew`. `Glad`, as far as I know` *does* require a valid current `OpenGL` context in order to operate correctly -- regardless of OS (someone please correct me if that's not the case). – G.M. Nov 18 '22 at 21:13
  • @G.M. Only if you enable the option mx or mx global (mx: multi context). See https://gen.glad.sh/ and https://github.com/Dav1dde/glad/wiki/C#multi-context. The activive context is only relevant as described in the OpenGl documentation. – Erdal Küçük Nov 18 '22 at 21:43

0 Answers0