OS 上的 OpenGL:着色器无法编译
OpenGL on OS : shader won't compile
我曾在 IOS 上使用 OpenGL ES,但现在我想尝试在 OS 上使用 OpenGl。我有非常基本的着色器用于测试,但不知何故,它无法编译?关于 OpenGl,有什么我需要了解的吗?那里有什么不同。
这里是着色器:
attribute vec4 position;
attribute vec2 texCoord;
attribute vec3 normal;
varying lowp vec2 vTexCoord;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
uniform mat3 normalMatrix;
void main()
{
vTexCoord = texCoord;
gl_Position = projectionMatrix*modelViewMatrix * position;
}
片段:
uniform sampler2D uSampler;
varying lowp vec2 vTexCoord;
void main()
{
lowp vec4 texCol = texture2D(uSampler, vTexCoord);
gl_FragColor = vec4(texCol.rgba);
}
出现的错误是:
错误:0:9:'vec2':语法错误:语法错误
精度说明符(lowp、mediump 和 highp)是 GLSLES 的一部分,而不是 GLSL,因此要在 GLSL 上编译,您应该删除它们。
如果你想在 GLSL 和 GLSLES 中使用相同的着色器源,那么你可以通过在着色器之前包含这样的字符串来#define 它们。
#define highp
#define mediump
#define lowp
我曾在 IOS 上使用 OpenGL ES,但现在我想尝试在 OS 上使用 OpenGl。我有非常基本的着色器用于测试,但不知何故,它无法编译?关于 OpenGl,有什么我需要了解的吗?那里有什么不同。
这里是着色器:
attribute vec4 position;
attribute vec2 texCoord;
attribute vec3 normal;
varying lowp vec2 vTexCoord;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
uniform mat3 normalMatrix;
void main()
{
vTexCoord = texCoord;
gl_Position = projectionMatrix*modelViewMatrix * position;
}
片段:
uniform sampler2D uSampler;
varying lowp vec2 vTexCoord;
void main()
{
lowp vec4 texCol = texture2D(uSampler, vTexCoord);
gl_FragColor = vec4(texCol.rgba);
}
出现的错误是:
错误:0:9:'vec2':语法错误:语法错误
精度说明符(lowp、mediump 和 highp)是 GLSLES 的一部分,而不是 GLSL,因此要在 GLSL 上编译,您应该删除它们。
如果你想在 GLSL 和 GLSLES 中使用相同的着色器源,那么你可以通过在着色器之前包含这样的字符串来#define 它们。
#define highp
#define mediump
#define lowp