3

I just started GLSL shader programing, but however I get unrecognized preprocessing directive whenever I put #version directive at the preprocessor directives header stack, though I included all opengl related headers and files within my source file,

Shader:

#version 400
in vec3 Color; 
out vec4 FragColor; 
void main() 
{ 
    FragColor = vec4(Color, 1.0); 
}

how can I fix this issue?

6
  • Did you specify which version you're using? Such as #version 150 Commented Nov 8, 2012 at 8:31
  • 3
    Post your source code (both glsl and the main application), opengl version and operating system. Commented Nov 8, 2012 at 8:32
  • As @JoakimGebart said, we can't help without more informations. Did you check your OpenGL version running? Commented Nov 8, 2012 at 8:39
  • @TheAmateurProgrammer for sure i specified the version but yet gives the same error!!! Commented Nov 8, 2012 at 8:42
  • @JoakimGebart well iam stuck at the point where the preprocessor directives are being declared (beginning of coding) my problem is that why #version is not considered as a directive in the first place !!! all of the other directives get highlighted except #version Commented Nov 8, 2012 at 8:45

2 Answers 2

2

The #version directive must occur in a shader before anything else, except for comments and white space.

Even preprocessor directives are illegal ( NVIDIA accepts it but AMD does not! ). If this doesn't help, give us some more information. E.g. glGetString(GL_VERSION) and glGetString(GL_VENDOR).

Refering to your comments you missunderstand how a shader is compiled. A shader cannot be compiled by a C++ compiler. Put your shader into a text file and load it at runtime, then call the compilation methods of OpenGL.

Sign up to request clarification or add additional context in comments.

9 Comments

this also gave me the same error!! is there any specific file regarding shader programs?? forexample i wrote mine in a .cpp file, and if the directive should come before any other directives how does the compiler identifies this as a valid preprocessor directive (since it is GLSL specific directive)
@user1788024 Please not so many !!!'s. Please post your shader, even if you say its simple. Than we can sure that there is no other issue.
'#version 400 in vec3 Color; out vec4 FragColor; void main() { FragColor = vec4(Color, 1.0); }'
@user1788024 A shader cannot be compiled by a C++ compiler by default. Shaders must be compiled by OpenGL on request. I gonna add it to my answer.
so that is the point, well now things make sense thank you for your time and effort.
|
0

The #version pre-processor command is run at the c++ compile time, glsl is only text based and shouldn't be compiled. If you #include "file" in a header or .cpp in the program it will trigger the compile and error. Therefore don't #include glsl files into you application.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.