我正在为openGl编写一个顶点着色器。这是我的代码:
#version 150
in vec4 vPosition;
in vec3 vNormal;
out vec3 fN;
out vec3 fE;
out vec3 fL;
uniform mat4 model_matrix;
uniform mat4 view_matrix;
uniform mat4 proj_matrix;
uniform vec4 lightPos;
void main()
{
vec3 pos = (view_matrix * model_matrix * vPosition).xyz;
vec3 lightPosInCam = (view_matrix * lightPos).xyz;
fN = normalize(view_matrix * model_matrix * vec4(vNormal,1.0)).xyz;
fE = normalize(vec3(0,0,0) - pos);
fL = normalize(lightPosInCam.xyz - pos);
gl_Position = proj_matrix*view_matrix*model_matrix*vPosition;
}
然而,当我运行我的程序时,似乎错误说我的}
之后有一些nonASCII字符,因为在控制台打印中:
#version 150
in vec4 vPosition;
in vec3 vNormal;
out vec3 fN;
out vec3 fE;
out vec3 fL;
uniform mat4 model_matrix;
uniform mat4 view_matrix;
uniform mat4 proj_matrix;
uniform vec4 lightPos;
void main()
{
vec3 pos = (view_matrix * model_matrix * vPosition).xyz;
vec3 lightPosInCam = (view_matrix * lightPos).xyz;
fN = normalize(view_matrix * model_matrix * vec4(vNormal,1.0)).xyz;
fE = normalize(vec3(0,0,0) - pos);
fL = normalize(lightPosInCam.xyz - pos);
gl_Position = proj_matrix*view_matrix*model_matrix*vPosition;
}═════════════════════════
Printed Shader Read Status
vshader_hw5.glsl failed to compile:
ERROR: 0:26: '' : illegal non-ASCII character (0xcd)
ERROR: 0:26: '' : illegal non-ASCII character (0xcd)
ERROR: 0:26: '' : illegal non-ASCII character (0xcd)
ERROR: 0:26: '' : illegal non-ASCII character (0xcd)
ERROR: 0:26: '' : illegal non-ASCII character (0xcd)
ERROR: 0:26: '' : illegal non-ASCII character (0xcd)
答案 0 :(得分:1)
然而,当我运行我的程序时,似乎错误说我的}之后有一些nonASCII字符,因为在控制台打印中:
这是当使用零字节(NUL)未正确终止到OpenGL的着色器源字符串和/或传递的缓冲区长度与源字符串的长度不匹配时遇到的典型错误。 / p>
解决方案:如果您没有显式传递长度(即为length参数传递NULL),请确保源字符串正确地为零终止。否则,请确保长度与源字符串缓冲区的长度正确匹配。