Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gl_Position is not accessible in this profile?

When trying to compile GLSL shaders in C/C++ using GLFW/GLEW I get the following error:

0(12) : error C5052: gl_Position is not accessible in this profile

I followed a tutorial from learnopengl.com. The code runs and displays a empty while square with the above error message being printed to the command line. Any ideas what is happening and how I might fix it?

The fragment shader is:

#version 410 

layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aColor;
layout (location = 2) in vec2 aTexCoord;

out vec3 ourColor;
out vec2 TexCoord;

void main()
{
    gl_Position = vec4(aPos, 1.0);
    ourColor = aColor;
    TexCoord = aTexCoord;
}

And the vertex shader is:

#version 410 

out vec4 FragColor;

in vec3 ourColor;
in vec2 TexCoord;

uniform sampler2D ourTexture;

void main()
{
    FragColor = texture(ourTexture, TexCoord);
}

If you would like to see the rest of the code please refer to the tutorial link above.

like image 513
Blunderchips Avatar asked Feb 17 '19 12:02

Blunderchips


1 Answers

Looks like you tried to load the fragment shader as the vertex shader and vice versa. gl_Position can only be set from within the vertex shader, since it's a per-vertex attribute. Loading the shaders in correct order should get rid of that problem though.

like image 151
peabrainiac Avatar answered Sep 17 '22 10:09

peabrainiac