问题描述
我正在关注《 OpenGL编程指南第8版》.我只想在Mac上运行本书中介绍的第一个程序.
I'm following book "OpenGL Programming Guide 8th Edition". I just want to run the first program introduced in the book on my Mac.
它是Mavericks + Xcode 4.6.1 + Intel HD graphics4000.所以问题是,无法编译着色器.
It's Mavericks + Xcode 4.6.1 + Intel HD graphics 4000. So the problem is, the shader can't be compiled.
着色器代码:
#version 410 core
layout(location = 0) in vec4 vPosition;
void
main()
{
gl_Position = vPosition;
}
错误消息是:
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
我尝试了420/400/330版,但没有一个起作用.
I tried version 420/400/330, none of them works.
顺便说一句,该程序使用最新的glew 1.10( http://glew.sourceforge.net ),并且我发现必须设置"glewExperimental = GL_TRUE;"在调用glewInit之前.否则,"glGenVertexArray"是NULL指针.所以我想知道也许不支持小牛吗?
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?
推荐答案
MacOS使用 旧版配置文件 作为所有创建的OpenGL上下文的默认设置.因此,默认情况下,仅支持OpenGL最高为2.1,GLSL最高为1.20.
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.
要使用OpenGL 3.2+,您需要切换到 核心配置文件 .命名有点混乱,因为它仅统计3.2Core配置文件,但实际上是3.2或更高版本(系统/驱动程序支持的向后兼容3.2的每个OpenGL配置文件)
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)
对于glut(取决于glut的版本,如果适用),MacOS上的命令为:
For glut (depends on the version of glut if it works) the command on MacOS is:
glutInitDisplayMode(GLUT_3_2_CORE_PROFILE | ... )
| ...
是要传递给glutInitDisplayMode
的其他选项.
Where | ...
would be the other options you want to pass to glutInitDisplayMode
.
关于glew
,由于在MacOS中实现OpenGL层的方式,通常在MacOS上不需要glew
.您只能使用MacOS提供/公开的OpenGL功能.因此,这些功能是否可以通过MacOS的标头使用.标头将是#include <OpenGL/gl3.h>
,其命名也令人误解,这不仅意味着OpenGL 3,而且与上下文相同.
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.
我建议使用 GLFW ,它是一个很棒的跨平台库,类似于GLUT
,但是我认为更好用.在那里,您将像这样切换上下文:
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);
这篇关于着色器无法编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!