BulBul
BulBul

Reputation: 1209

GLSL shader programming #version header error: unrecognized preprocessing directive

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?

Upvotes: 3

Views: 13286

Answers (2)

GrimCobra
GrimCobra

Reputation: 1

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.

Upvotes: 0

Felix K.
Felix K.

Reputation: 6281

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.

Upvotes: 2

Related Questions