Only glsl shader version 120 works on mac OS X

家住魔仙堡 提交于 2019-12-06 12:57:29

问题


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



来源:https://stackoverflow.com/questions/23630096/only-glsl-shader-version-120-works-on-mac-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!