<p>The issue was that I declared <code>out vec3 gModelPosition[]</code> as an array in my geometry shader.</p>

<p>It should have only been declared as a <code>vec3</code> (i.e. <code>out vec3 gModelPosition</code>)</p>

CC BY-SA 3.0
2017-10-27T03:51:01.957Z
You should also write to them the same way you write to `gl_Position`: before calling `EmitVertex()`.
Nicol Bolas
CC BY-SA 3.0
2017-10-25T22:17:27.853Z
2017-10-25T22:17:27.853Z
Startec
<p>I am trying to pass vertex attributes from my vertex shader -> geometry shader and then to the fragment shader.</p>

<p>Pretty simple program, here is my vertex shader:</p>

<pre><code>#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;
}
</code></pre>

<p>Here is my geometry shader:</p>

<pre><code>#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 &lt; 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();
}
</code></pre>

<p>And here is my fragment shader:</p>

<pre><code>#version 440 core

in vec3 gModelPosition;

out vec4 fragColor;

void main()
{
    fragColor = vec4(gModelPosition, 1.0);
}
</code></pre>

<p>I get the following error:</p>

<pre><code>PROGRAM_LINKING_ERROR: error: "gModelPosition" not declared as input from previous stage
</code></pre>

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

<p>Am I doing something wrong here?</p>

CC BY-SA 3.0
2017-10-25T21:55:34.467Z
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.
Dan Hulme
<opengl><glsl><geometry-shader>
Issue with declaring inputs to geometry shader?
Startec
# Issue with declaring inputs to geometry shader?

(Asked by: username_0 on 2017-10-25)

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;
}

```

Here is my geometry shader:

```
#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?

**Tags:** opengl, glsl, geometry-shader

> **Comments:**
> **username_1**: 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.  

---

## 1 answers

### Answer by username_0 on 2017-10-25. Score: 2 | Accepted answer

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`)

> **Comments:**
> **username_2**: You should also write to them the same way you write to `gl_Position`: before calling `EmitVertex()`.  

---

