Shader cannot be compiled

I follow the book "OpenGL Programming Guide 8th Edition". I just want to run the first program presented in a book on my Mac.

It Mavericks + Xcode 4.6.1 + Intel HD Graphics 4000. So the problem is that the shader cannot be compiled.

Shader Codes:

#version 410 core layout(location = 0) in vec4 vPosition; void main() { gl_Position = vPosition; } 

And the error message:

 Shader compilation failed: ERROR: 0:1: '' : version '410' is not supported ERROR: 0:1: '' : syntax error #version ERROR: 0:3: 'layout' : syntax error syntax error 

I tried version 420/400/330, none of them work.

By the way, the program uses the latest glew 1.10 ( http://glew.sourceforge.net ), and I found that I need to set "glewExperimental = GL_TRUE;" before calling glewInit. Otherwise, "glGenVertexArray" is a NULL pointer. So I'm wondering, maybe glew doesn't support Mavericks?

+8
osx-mavericks shader opengl glut
source share
2 answers

MacOS uses the default Legacy Profile for the entire OpenGL context created. Therefore, by default, only OpenGL up to 2.1 and GLSL up to 1.20 are supported.

To use OpenGL 3.2+, you need to switch to the Main profile . The naming there is a bit confusing because it only defines the 3.2Core profile, but it is actually 3.2 or newer (each OpenGL profile is supported by the system / driver, which is backward compatible with 3.2)

For a glut (depending on the glut version, if it works) the command on MacOS is:

 glutInitDisplayMode(GLUT_3_2_CORE_PROFILE | ... ) 

Where | ... | ... will be other parameters that you want to pass to glutInitDisplayMode .

About glew , you usually don't need glew on MacOS because of the way the OpenGL layer is implemented on MacOS. You are limited by the OpenGL features provided / provided by MacOS. Thus, either functions are available through MacOS headers or not. There, the title will be #include <OpenGL/gl3.h> , where naming is also a pass, this does not mean only OpenGL 3, it is the same as in the context.

I would recommend using GLFW , this is a great cross-platform library, similar to GLUT , but it seems to me better to use. There you would switch the context as follows:

  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); 
+21
source share

Your driver may not support the required version of GLSL. I had this problem on a laptop with an Intel HD card on a new Ubuntu installation six months ago.

Use glGetString to find out which version is available to you: http://www.opengl.org/sdk/docs/man/xhtml/glGetString.xml . For example,

 printf("Supported GLSL version is %s.\n", (char *)glGetString(GL_SHADING_LANGUAGE_VERSION)); 

Here you can find about glewExperimental: http://www.opengl.org/wiki/Extension_Loading_Library

+5
source share

All Articles