skaslev / gl3w

Simple OpenGL core profile loading
http://github.com/skaslev/gl3w
The Unlicense
709 stars 160 forks source link

glfw_test.c issue on Mac #42

Closed mhalber closed 7 years ago

mhalber commented 7 years ago

Hi there,

I've been recently testing out gl3w and I was trying to compile&run provided examples. While compiling the test.c which uses glut worked correctly, the glfw_test.c results in a segfault. I've tried to track the issue with gdb and the code seems to be failing in _parseversion function, specifically a call to glGetIntegerv, complaining about unknown type.

I was wondering if someone else has encountered such issue? I am running a mac os 10.11.6, and my compilation command is:

clang -framework Cocoa -framework IOKit -framework OpenGL src/glfw_test.c src/gl3w.c -Iinclude -lglfw3 -ldl -ggdb -o test_gl3w

Thanks!

tombsar commented 7 years ago

Sorry I didn't (and don't) have access to a Mac to test/debug this code.

If you add the following line:

glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

to main just before glfwCreateWindow, does it fix the error?

mhalber commented 7 years ago

Thanks! That made it work - any clue why that was necessary? Would be very interested to learn.

Edit: From a quick read of the glfw docs (http://www.glfw.org/faq.html - section 1.5) it appears that apple only provides modern profiles that are forward-compatible. Could it be that without it an incorrect context is created?

tombsar commented 7 years ago

You're welcome! Yes, unfortunately MacOS only provides forward-compatible profiles.

I would have thought that without that hint context creation would fail completely, but the segfault indicates that something else is happening.

@skaslev I suggest we add the FORWARD_COMPAT hint to the example code, and also investigate why the segfault occurs instead of exiting with an error.