Elmi
Elmi

Reputation: 6213

Compiling vertex shader program fails

I'm doing my first steps with OpenGL and stumbled upon a problem in my vertex shader program:

#version 330 core
layout (location = 0) in vec3 aPos;
uniform mat4 inputTransform;
void main()
{
   gl_Position = inputTransform * vec4(aPos, 1.0);
}

compiles and works well, but when I change the first line to

#version 130 core

because I'm bound to use OpenGL 3.0 at max, it first complains about the "location" statement. When I remove it, the remaining error message for the line

layout in vec3 aPos;

is

ERROR: 0:2: 'in' : syntax error syntax error

What's wrong here - how do I have to declare input variables in this version of the language?

Upvotes: 2

Views: 346

Answers (1)

Rabbid76
Rabbid76

Reputation: 211258

Input layout qualifiers have been added in GLSL version 1.50 wich corresponds to OpeneGL version 3.2

See OpenGL Shading Language 1.50 Specification; - 4.3.8.1 Input Layout Qualifiers; page 37.

An input layout qualifier consists of the keyword layout followed by the layout-qualifier-id-list.
It is not sufficient to remove the layout-qualifier-id-list alone, you have to remove the keyword layout too:

in vec3 aPos;

The syntax error is caused by the fact, that it is not a proper syntax, that layout is directly followed by in.


Either you have to ask for the attribute index by glGetAttribLocation after the program is linked, or you have to specify the attribute location by glBindAttribLocation before the shader program is linked.

Upvotes: 4

Related Questions