4

I saw a similar question here: OpenGL 4.1(?) under Mavericks, but it seems that person is relying on glut, so the solution doesn't apply.

I'm on OSX 10.9 (Mavericks), with an NVidia GeForce 650, developing in C++, using GLEW and GLFW.

I'm not using xcode- keeping it simple with a very basic makefile.

Anyways- I have these 5 lines of code:

window = glfwCreateWindow(640,480,"hello world",NULL,NULL);
glfwMakeContextCurrent(window);
glewExperimental = GL_TRUE;
glewInit();

printf("shader lang: %s\n",glGetString(GL_SHADING_LANGUAGE_VERSION));

and it prints out

shader lang: 1.2

I'm assuming setting glewExperimental should handle correctly getting the core context? (/ the stuff the other dude was talking about in the other thread)

What else do I need to do to enable the latest shader versions?

Ps- my full code is here, including the makefile: https://github.com/Phildo/openglexp , but I'm not sure how useful it will be.

Community
  • 1
  • 1
Phildo
  • 986
  • 2
  • 20
  • 36
  • 1
    What glfw window hints are you using? You need major version 3, minor version 2, core, forward compatible on OS X. – Andon M. Coleman Nov 14 '13 at 05:08
  • @AndonM.Coleman Thanks so much! Out of curiosity- where/how did you find this information? I looked everywhere for it... – Phildo Nov 14 '13 at 05:15
  • 2
    GLFW does not document this that I am aware of. I know this information because I work with the low-level OpenGL context management APIs (CGL / NSOpenGL) for my work. Apple documents it in various places, such as [here](https://developer.apple.com/library/mac/documentation/graphicsimaging/conceptual/opengl-macprogguide/opengl_pixelformats/opengl_pixelformats.html) – Andon M. Coleman Nov 14 '13 at 05:20

2 Answers2

8

I have never used GLFW before, but according to the API documentation and my thorough experience with low-level OS X GL context management, the following code should fix your problem:

glfwInit       ();

glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint (GLFW_OPENGL_PROFILE,        GLFW_OPENGL_CORE_PROFILE);

Make sure you call these things before glfwCreateWindow (...)

Andon M. Coleman
  • 42,359
  • 2
  • 81
  • 106
  • You also need the line `glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);`. See http://www.glfw.org/docs/latest/compat.html#compat_osx – Leo Apr 29 '14 at 00:11
  • Oops. I must not have noticed it because of the spacing. – Leo Apr 30 '14 at 02:05
0

For anyone else trying to get this to work - the above answers are correct. You need to add all of the aforementioned glfwWindowHints. However, this didn't immediately work for me UNTIL I moved the hints AFTER the call to glfwInit() and BEFORE glfwCreateWindow(). Thanks all for the help.

mike
  • 333
  • 1
  • 2
  • 7