0

I've been staring at this for too long and I'm too new to GLSL to know what is wrong. All I know is that when checking to see if the vertex shader compiles, it says that it could not do so. If someone could help me find out what I've done wrong that would be amazing.

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); } 

What I'm doing to check the compilation. DBOUT is a function to write to the Visual Studio output box.

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(); } 

The output I receive:

Couldn't Compile Vertex Shader: Aborting Mission Debug Error! 

SOLVED

So with everyones help I go this to compile. I had to replace these lines:

 gl_TexCoord[0] = gl_MultiTexCoord0; gl_Position = position; 

With these ones:

 TextCoord = vec2(textCoord); gl_Position = mvpMatrix * vec4(position,1.0f); 

Thank you everyone!

3
  • 1
    grab the log with glGetShaderInfoLog​ and print that Commented Mar 18, 2015 at 21:20
  • Check logs, post MCVE, etc. Make sure your #version directive line has a newline at the end. Commented Mar 18, 2015 at 22:10
  • @ratchetfreak printing the info log gives me the following E Commented Mar 18, 2015 at 22:25

2 Answers 2

3

I didn't look at your shader but you can get an error message from the compiler with something like:

auto error = GLint(); ::glGetShaderiv(id, GL_COMPILE_STATUS, &error); if(error != GL_TRUE) { auto length = GLint(); ::glGetShaderiv(id, GL_INFO_LOG_LENGTH, &length); if(length > 0) { auto log = std::vector<GLchar>(length, 0); ::glGetShaderInfoLog(id, length, nullptr, &log[0]); auto message = std::string(log.begin(), log.end()); ... } } 
Sign up to request clarification or add additional context in comments.

2 Comments

Gotta say... I don't see much use in declaring something auto if you have the compiler deduce its type by writing = GLint(). Seems like you could save a lot of typing if you didn't use auto.
I use auto everywhere and that kind of declaration ensures it's always initialised. The compiler can't deduce the type given the variable's future use (unfortunately). It's just a general rule I use.
1

One possible error in the shader might be:

gl_Position = position;

The gl_Position should be of type vec4, but the position is an attribute of vec3, you probably forgot to do something like:

gl_Position = mvpMatrix * vec4(position, 1.0f);

2 Comments

Changing that gave me a different error, so I'm not totally sure if it's just one thing going wrong. After making this change I get a new error (checked with glGetError()) on this call: glEnableVertexAttribArray(tCoordLoc[i]);
Ok so the shader error has gone away, right? The glEnableVertexAttribArray is not part of the shown code so I am not sure, but I guess that you pass the wrong argument. This function is used to enable the vertexAttribs that you specify using glVertexAttribPointer and not the location of a uniform.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.