PDA

View Full Version : Syntax error using gl_FragDepth



somedave
11-03-2015, 06:58 PM
Hi folks,

I am getting the following error when doing a glCompileShader() on my frag shader code:

error C0000: syntax error, unexpected $undefined, expecting "::" at token "<undefined>"

The line of code that is complaining about is:

gl_FragDepth​ = 1.0f;

I have never seen this error ever. Any idea what might cause that?

For the record, I tried explicitly setting my shader version to
#version 120
and also a newer version
#version 150
Same error. Any help decoding this error would be greatly appreciated.

Alfonse Reinheart
11-03-2015, 08:39 PM
The line of code that is complaining about is

First rule of compiler errors: just because it lists that line does not mean that it's the cause of the error. That's just where the compiler realized that something was wrong. If a line of code looks innocuous, that means the error probably happened somewhere before then.

Even more confusing is that `::` is not a token of GLSL. It should never be something the compiler expects. So I'm going to go out on a limb and suggest that you're probably passing the shader text to OpenGL incorrectly.

Oh, and #version declarations should not be considered optional (https://www.opengl.org/wiki/Core_Language_%28GLSL%29#Version).

somedave
11-04-2015, 09:46 AM
First rule of compiler errors: just because it lists that line does not mean that it's the cause of the error. That's just where the compiler realized that something was wrong. If a line of code looks innocuous, that means the error probably happened somewhere before then.

Even more confusing is that `::` is not a token of GLSL. It should never be something the compiler expects. So I'm going to go out on a limb and suggest that you're probably passing the shader text to OpenGL incorrectly.

And, it turns out that the problem was that MSVC was putting some garbage chars in the raw text, and hiding it from my view. I looked at the file in another editor and saw this:

gl_FragDepth​ = 1.0f;

Works fine when I clean that up.


Oh, and #version declarations should not be considered optional (https://www.opengl.org/wiki/Core_Language_%28GLSL%29#Version).

Good to know. Thanks!

Alfonse Reinheart
11-04-2015, 11:49 AM
FYI if you're curious about where that character came from. (http://stackoverflow.com/questions/2477452/%C3%A2%E2%82%AC-showing-on-page-instead-of)