gl_Position is not accessible in this profile?
Asked Answered
M

1

13

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.

Miquelmiquela answered 17/2, 2019 at 12:26 Comment(2)
The first code block should be the vertex shader, the second one the fragment shader. If this is not just a typo in the question, then this is probably the reason for the error message (there is no gl_Position in a fragment shader).Lauretta
While this is indeed a "stupid mistake", the error message "gl_Position is not accessible in this profile" turns out to be very indicative of this (rather common) beginner-level mishap. The answer saved me a lot of time, too. The upvote count on the answer also show that this closed question has helped many people. I thus vote to reopen this question.Struggle
P
32

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.

Principe answered 17/2, 2019 at 13:6 Comment(4)
Thank you. A simple error that I never noticed.Miquelmiquela
One reason to abolish "closed" - I had this exact problem, and this question lead me straight to the solution.Tiresome
If you are loading your shaders from a file, make sure you load the correct shader too. I tried to load a fragment shader from my vertex shader file and ended up here :DHandstand
I don't even use C/C++ yet still had the same problem. Thank you!Creep

© 2022 - 2024 — McMap. All rights reserved.