# Issue with declaring inputs to geometry shader?

I am trying to pass vertex attributes from my vertex shader -> geometry shader and then to the fragment shader.

Pretty simple program, here is my vertex shader:

#version 440 core

uniform mat4 uModelViewMatrix;
uniform mat4 uProjMatrix;

in vec4 aPosition;

out vec3 modelPosition;

void main()
{
modelPosition = aPosition.xyz;
gl_Position = uProjMatrix * uModelViewMatrix * aPosition;
}


#version 440 core

layout (triangles) in;
layout (triangle_strip, max_vertices = 3) out;

in vec3 modelPosition[];

out vec3 gModelPosition[];

void main()
{
for (int i = 0; i < gl_in.length(); i++)
{
gl_Position = gl_in[i].gl_Position;
EmitVertex();
}
gModelPosition[0] = modelPosition[0];
gModelPosition[1] = modelPosition[1];
gModelPosition[2] = modelPosition[2];
EndPrimitive();
}


And here is my fragment shader:

#version 440 core

in vec3 gModelPosition;

out vec4 fragColor;

void main()
{
fragColor = vec4(gModelPosition, 1.0);
}


I get the following error:

PROGRAM_LINKING_ERROR: error: "gModelPosition" not declared as input from previous stage


If I just comment out the last line in the fragment shader, and say fragColor = vec4(1.0); it works fine. And I clearly am declaring gModelPosition as an input from the previous stage.

Am I doing something wrong here?

• If you solved your problem yourself, you can answer your own question. Deleting it just means the next person with a similar problem won't get the benefit of your experience. Oct 25 '17 at 21:55

The issue was that I declared out vec3 gModelPosition[] as an array in my geometry shader.
It should have only been declared as a vec3 (i.e. out vec3 gModelPosition)
• You should also write to them the same way you write to gl_Position: before calling EmitVertex(). Oct 27 '17 at 3:51