I am writing down my own shaders for the OpenGL in python:
I have written down these 2 shaders:
Vertex Shader:
#version 330 core
layout(location=0) in vec3 vertexPos;
out vec4 position;
void main()
{
position = vec4(vertexPos,1.0);
}
Fragment Shader:
#version 330 core
layout(location=1) in vec3 vertexColor;
out vec4 color;
void main()
{
color = vec4(vertexColor,1.0);
}
The shaders are correct right? OpenGL wont produce a error,right?
Edit:
I have debugged it and it prints me out this message:
OpenGL.GL.shaders.ShaderCompilationError: ('Shader compile failure (0): b\'Fragment shader failed to compile with the following errors:\\nERROR: 2:1: error(#5) Extension: "explicit attribute location in fragment shader is only supported for the out storage qualifier"\\nERROR: error(#273) 1 compilation errors. No code generated\\n\\n\'', [b'#version 330 core\n', b'\n', b'layout(location=1) in vec3 vertexColor;\n', b'\n', b'out vec4 color;\n', b'\n', b'void main()\n', b'{\n', b'color = vec4(vertexColor,1.0);\n', b'}\n', b'\n'], GL_FRAGMENT_SHADER)
But why is the vertex shader compilable while the fragment shader is not compilable?
The fragment shader cannot directly process the vertex attribute. You need to pass the attributes from the vertex to the fragment shader. Additionally the vertx shader must write to
gl_Position(regardless of the version of the shader):Vertex Shader:
Fragment Shader:
OpenGL Shading Language 4.60 Specification - Vertex Shader Special Variables: