GLSL Vertex Shader not compiling

Started by
1 comment, last by _paf 11 years, 4 months ago
Hi everyone.

So, i made a program in OpenGL using 2 different shader programs. One for 2D geometry and another for 3D geometry, both using two different vertex shaders, and the same fragment shader (whichi will post below).

Ah, before saying anything else, let me say i'm using Visual C++ 2010 Express edition, and running the program in 'Debug' mode.

I tested the program and everything worked fine, until i switched the building to 'Release' mode on the IDE, which made the 2D vertex shader and the fragment shader stop compiling, leaving only the 3D vertex shader working.

The errors were the same for both shaders:

Vertex(Fragment) shader failed to compile with the following errors:
ERROR: 0:15: error(#132) Syntax error: '<' parse error
ERROR: error(#273) 1 compilation errors. No code generated

By the way the shaders are these:

2D_Vertex.glsl

#version 330 core

in vec3 in_Position;
in vec2 in_TexCoords;

smooth out vec2 pass_TexCoords;

uniform mat4 uni_OrthoMatrix;

void main(void)
{

pass_TexCoords = in_TexCoords;
gl_Position = uni_OrthoMatrix * vec4(in_Position, 1.0);

}


3D_Vertex.glsl

#version 330 core

in vec3 in_Position;
in vec2 in_TexCoords;
in vec3 in_Normal;

smooth out vec2 pass_TexCoords;

uniform mat4 uni_PerspectiveViewMatrix;
uniform mat4 uni_ModelMatrix;
uniform mat3 uni_NormalMatrix;

void main(void)
{

pass_TexCoords = in_TexCoords;
gl_Position = uni_PerspectiveViewMatrix * uni_ModelMatrix * vec4(in_Position, 1.0);

}


Fragment.glsl

#version 330 core

smooth in vec2 pass_TexCoords;

uniform sampler2D uni_Texture0;

void main(void)
{

gl_FragColor = texture(uni_Texture0, pass_TexCoords);

}


So first i checked the fragment shader for something wrong, and the part that shows 'gl_FragColor = texture(...', i changed the 'texture' to 'texture2D', thinking maybe it wasn't supported in version 330 (even though it compiled fine on 'Debug' mode), and it worked, it compiled successfully.

Now the thing is, i can't find anything wrong in the 2D_Vertex shader, and it won't compile (and as i said before, the program works perfectly on 'Debug' mode).

All the uniform variables are correct for all shader programs, so the problem has to be in the shader.

The program does have an OpenGL 3.3 core profile (don't know if it helps, but...)
Oh, and i also tried changing/removing the #version tag, to no avail.

Any help is appreciated.

Thanks in advance!
Advertisement
Switching your build target will not change the way your shaders get compiled. I would assume, that something is broken in the code that loads the shaders from disc and passen them on to OpenGL. Can you post that code?
Absolutely right!

It seemed odd as why it wouldn't compile, and i somehow put in my mind the idea that the problem had to be with OpenGL. But after reading your answer i went back to check the code for reading the shader from disk, and i found it.

I forgot to initialize the text buffer for the shader read as NULL, so the string of text passed to OpenGL had a couple random characters at the end of the string, and i'm gessing the reason it compiled in debug mode may be because there are some safety checks that allow this, but are removed in release mode...

Well many thanks, and i really have to remenber to initialize things to a known value!

This topic is closed to new replies.

Advertisement