我一直盯着這個太久了,我對GLSL來說太陌生,不知道什麼是錯的。我所知道的是,當檢查頂點着色器是否編譯時,它說它不能這樣做。如果有人能幫我找出我做錯了什麼,那將是驚人的。GLSL着色器不會編譯,有人可以幫我找出原因嗎?
textureShader.vert
#version 140
uniform mat4 mvpMatrix;
attribute vec3 position;
attribute vec2 textCoord;
varying vec2 TextCoord;
varying vec3 lightDir,normal;
void main()
{
normal = normalize(gl_NormalMatrix * gl_Normal);
lightDir = normalize(vec3(gl_LightSource[0].position));
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = position;
}
textureShader.frag
#version 140
uniform sampler2D texUnit;
varying vec2 TextCoord;
varying vec3 lightDir,normal;
void main()
{
vec3 ct,cf;
vec4 texel;
float intensity,at,af;
intensity = max(dot(lightDir,normalize(normal)),0.0);
cf = intensity * (gl_FrontMaterial.diffuse).rgb + gl_FrontMaterial.ambient.rgb;
af = gl_FrontMaterial.diffuse.a;
texel = texture2D(texUnit, TextCoord);
ct = texel.rgb;
at = texel.a;
gl_FragColor = vec4(ct * cf, at * af);
}
我在做什麼檢查彙編。 DBOUT是寫入Visual Studio輸出框的函數。
glCompileShader(shader_vp);
validateShader(shader_vp, vsFile);
GLint compiled;
glGetShaderiv(shader_vp, GL_COMPILE_STATUS, &compiled);
if (!compiled){
DBOUT("Couldn't Compile Vertex Shader: Aborting Mission\n");
abort();
}
glCompileShader(shader_fp);
validateShader(shader_fp, fsFile);
glGetShaderiv(shader_fp, GL_COMPILE_STATUS, &compiled);
if (!compiled){
DBOUT("Couldn't Compile Fragment Shader: Aborting Mission\n");
abort();
}
輸出我得到:
Couldn't Compile Vertex Shader: Aborting Mission
Debug Error!
解決
因此,與大家的幫助,我走這編譯。我不得不更換這些線路:
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = position;
有了這些的:
TextCoord = vec2(textCoord);
gl_Position = mvpMatrix * vec4(position,1.0f);
謝謝大家!
用glGetShaderInfoLog獲取日誌並打印 – 2015-03-18 21:20:30
檢查日誌,發佈MCVE等。確保你的'#version'指令行在最後有一個換行符。 – genpfault 2015-03-18 22:10:30
@ratchetfreak打印信息日誌給我以下 E – 2015-03-18 22:25:14