Search code examples
c++glslshader

ERROR: 0:1: '' : Version number not supported by GL2


I'm trying to make shader, but it gives me this error:

ERROR: 0:1: ' ' :  Version number not supported by GL2
ERROR: 0:3: 'layout' : syntax error parse error

Please help! This is my vertex shader code:

#version 330
        
layout(location = 0) in vec4 position;
void main()
{
gl_Position = position;
}

And this is my fragment shader code:

#version 330

layout(location = 0) out vec4 color;
void main()
{
color = vec4(1.0, 0.0, 0.0, 1.0);
}

I tried making the version lower, but it doesn't work.


Solution

  • Since your graphics driver and card only support OpenGL 2.0, you cannot use a GLSL shader with version 3.30. You need to use GLSL 1.10 which corresponds to OpenGL 2.0.
    See OpenGL Shading Language 1.10 Specification and OpenGL specification - Khronos OpenGL registry

    An appropriate shader would be:

    Vertex shader

    #version 110
            
    attribute vec4 position;
    
    void main()
    {
        gl_Position = position;
    }
    

    Fragment shader

    #version 110
    
    void main()
    {
        gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
    }