Only glsl shader version 120 works on mac OS X

2020-07-28 12:06发布

问题:

I have a problem with the glsl's version on my mac os X 10.9.2. I'm making a program in c++ with OpenGL and SDL2

I can't upgrade from my version 120 to any version higher. How I can upgrade please ? I compile like this :

g++ and my flag is : -framework SDL2 -lSDLmain -framework OpenGL -framework SDL2_image -framework cocoa

ERROR: 0:3: '' : version '330' is not supported

回答1:

On OS/X 10.9 to create an OpenGL 3.3/4.1 context you need to add the following snippet before SDL_CreateWindow.

  SDL_Init(SDL_INIT_VIDEO); 
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
  // ...
  // auto window = SDL_CreateWindow(...)
  // auto context = SDL_GL_CreateContext(window);
  cout << "OpenGL version " << glGetString​(GL_VERSION​) << endl;
  cout << "GLSL version " << glGetString​(GL_SHADING_LANGUAGE_VERSION​​) << endl;

A full example is available here: https://gist.github.com/mortennobel/643e92bd6a63de688c6f