I'm following book "OpenGL Programming Guide 8th Edition". I just want to run the first program introduced in the book on my Mac.
It's Mavericks + Xcode 4.6.1 + Intel HD graphics 4000. So the problem is, the shader can't be compiled.
Shader codes:
#version 410 core
layout(location = 0) in vec4 vPosition;
void
main()
{
gl_Position = vPosition;
}
And the error message is:
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 works.
By the way, the program uses latest glew 1.10(http://glew.sourceforge.net), and I found that I have to set "glewExperimental = GL_TRUE;" before calling glewInit. Otherwise "glGenVertexArray" is a NULL pointer. So I'm wondering maybe glew doesn't support Mavericks?
Shader Compilation is the term used to describe the process by which OpenGL Shading Language scripts are loaded into OpenGL to be used as shaders. OpenGL has three ways to compile shader text into usable OpenGL objects. All of these forms of compilation produce a Program Object.
Unlike PC, many consoles cannot compile shaders locally.
When linking a shader program, OpenGL makes the connections between input and output variables in the vertex and fragment shaders (among other things). If a vertex shader's output variable has the same name and type as a fragment shader's input variable, OpenGL will automatically link them together.
MacOS uses Legacy Profile as default for all created OpenGL context. Therefor by default only OpenGL up to 2.1 and GLSL up to 1.20 is supported.
To use OpenGL 3.2+ you need to switch to the Core Profile. The naming there is a little bit confusing because it stats only 3.2Core profile, but actually this 3.2 or later (every OpenGL profile that is supported by the system/driver that is backwards compatible to 3.2)
For glut (depends on the version of glut if it works) the command on MacOS is:
glutInitDisplayMode(GLUT_3_2_CORE_PROFILE | ... )
Where | ...
would be the other options you want to pass to glutInitDisplayMode
.
About glew
, normally you don't require glew
on MacOS due the way how the OpenGL layer is implemented in MacOS. You are restricted to the OpenGL features MacOS provides/exposes. So either the features are available via the headers of MacOS or not. There header would be #include <OpenGL/gl3.h>
where also the naming is missleading, it does not mean only OpenGL 3, it is the same like with the context.
I would recommend to use GLFW it is a great cross platform library similar to GLUT
but as I think better to use.
There you would switch the context like this:
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);
It can be that your driver does not support the GLSL version you require. I had this problem on a laptop with Intel HD card on fresh install of Ubuntu half a year ago.
Use glGetString to figure 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With