<p>You are setting <code>g_color</code> after the vertex have been emitted so it will have no effect. <code>EmitVertex()</code> will emit the poition and whatever values are current in the out attributes. Set the attribute before emitting the vertex.</p>
<p>The gemometry shader can create geometry by emitting multiple vertices or destroy geometry by not emitting something. This is why the order of the <code>Emit</code> functions are very important.</p>
<p>The second issue is that you are enabling <code>PROGRAM_POINT_SIZE</code>. This requires the shader to set <code>gl_PointSize</code>. If this is not set the behaviour is undefined. Depending on drivers the default point size might be 0 or 1. It seems intel drivers use 0 as the default causing the point to be discarded.</p>

CC BY-SA 4.0
2021-08-14T15:07:15.210Z
2021-08-14T16:29:18.650Z
2021-08-14T16:29:18.650Z
Grimmy
<p>I am trying a simple passthrough just to get a feel for the geometry shader. I am taking in a single point and trying to output that point from the geometry shader, it works with the vertex and fragment shaders, but when I add in the geometry shader I get no output. There are no compilation errors neither.</p>
<p>I am using python's moderngl and have it set to render as points with <code>vao.render(moderngl.POINTS)</code>.</p>
<p><strong>vertex shader</strong></p>
<pre><code>#version 330

in vec3 point;
in vec4 color;

out vec3 v_point;
out vec4 v_color;

void main(){
    v_point = point;
    v_color = color;
}
</code></pre>
<p><strong>geometry shader</strong></p>
<pre><code>#version 330

layout (points) in;
layout (points, max_vertices=1) out;

in vec3 v_point[1];
in vec4 v_color[1];

out vec4 g_color;

void main() {
    gl_Position = vec4(v_point[0], 1.0);
    EmitVertex();
    EndPrimitive();
    g_color = v_color[0];
}
</code></pre>
<p><strong>fragment shader</strong></p>
<pre><code>#version 330

in vec4 g_color;

out vec4 f_color;

void main() {
    f_color = g_color;
}
</code></pre>
<p><strong>python code:</strong></p>
<pre class="lang-py prettyprint-override"><code>import moderngl
import numpy as np

from PIL import Image

ctx = moderngl.create_standalone_context()

shaders_source = {}

with open(&quot;vert_test.glsl&quot;, &quot;r&quot;) as f:
    shaders_source['vertex_shader'] = f.read()

with open(&quot;geom_test.glsl&quot;, &quot;r&quot;) as f:
    shaders_source['geometry_shader'] = f.read()

with open(&quot;frag_test.glsl&quot;, &quot;r&quot;) as f:
    shaders_source['fragment_shader'] = f.read()

prog = ctx.program(**shaders_source)

points = np.array([
    [0.0, 0.0, 0.0, 1, 0, 0, 1],
])

ctx.enable(moderngl.PROGRAM_POINT_SIZE)
vbo = ctx.buffer(points.astype('f4').tobytes())
vao = ctx.simple_vertex_array(prog, vbo, 'point', 'color')

fbo = ctx.simple_framebuffer((512, 512))

fbo.use()

fbo.clear(0.0, 0.0, 0.0, 1.0)

vao.render(moderngl.POINTS)

Image.frombytes('RGB', fbo.size, fbo.read(), 'raw', 'RGB', 0, -1).show()
</code></pre>

<opengl><geometry-shader>
Opengl geometry shader input point to output point doesn't show any ouput
Ryan McCauley
# Opengl geometry shader input point to output point doesn't show any ouput

(Asked by: username_0 on 2021-08-09)

I am trying a simple passthrough just to get a feel for the geometry shader. I am taking in a single point and trying to output that point from the geometry shader, it works with the vertex and fragment shaders, but when I add in the geometry shader I get no output. There are no compilation errors neither.

I am using python's moderngl and have it set to render as points with `vao.render(moderngl.POINTS)`.

**vertex shader**

```
#version 330

in vec3 point;
in vec4 color;

out vec3 v_point;
out vec4 v_color;

void main(){
    v_point = point;
    v_color = color;
}

```

**geometry shader**

```
#version 330

layout (points) in;
layout (points, max_vertices=1) out;

in vec3 v_point[1];
in vec4 v_color[1];

out vec4 g_color;

void main() {
    gl_Position = vec4(v_point[0], 1.0);
    EmitVertex();
    EndPrimitive();
    g_color = v_color[0];
}

```

**fragment shader**

```
#version 330

in vec4 g_color;

out vec4 f_color;

void main() {
    f_color = g_color;
}

```

**python code:**

```py
import moderngl
import numpy as np

from PIL import Image

ctx = moderngl.create_standalone_context()

shaders_source = {}

with open("vert_test.glsl", "r") as f:
    shaders_source['vertex_shader'] = f.read()

with open("geom_test.glsl", "r") as f:
    shaders_source['geometry_shader'] = f.read()

with open("frag_test.glsl", "r") as f:
    shaders_source['fragment_shader'] = f.read()

prog = ctx.program(**shaders_source)

points = np.array([
    [0.0, 0.0, 0.0, 1, 0, 0, 1],
])

ctx.enable(moderngl.PROGRAM_POINT_SIZE)
vbo = ctx.buffer(points.astype('f4').tobytes())
vao = ctx.simple_vertex_array(prog, vbo, 'point', 'color')

fbo = ctx.simple_framebuffer((512, 512))

fbo.use()

fbo.clear(0.0, 0.0, 0.0, 1.0)

vao.render(moderngl.POINTS)

Image.frombytes('RGB', fbo.size, fbo.read(), 'raw', 'RGB', 0, -1).show()

```

**Tags:** opengl, geometry-shader


---

## 1 answers

### Answer by username_1 on 2021-08-14. Score: 2 | Accepted answer

You are setting `g_color` after the vertex have been emitted so it will have no effect. `EmitVertex()` will emit the poition and whatever values are current in the out attributes. Set the attribute before emitting the vertex.

The gemometry shader can create geometry by emitting multiple vertices or destroy geometry by not emitting something. This is why the order of the `Emit` functions are very important.

The second issue is that you are enabling `PROGRAM_POINT_SIZE`. This requires the shader to set `gl_PointSize`. If this is not set the behaviour is undefined. Depending on drivers the default point size might be 0 or 1. It seems intel drivers use 0 as the default causing the point to be discarded.


---

