Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 698
BulBul Avatar asked Mar 11 '26 04:03

BulBul


1 Answers

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.

like image 147
Felix K. Avatar answered Mar 13 '26 06:03

Felix K.