-3

I am reading the OpenGL Superbible 7th edition. It is a great book and all, but when I get to the Geometry Shader part of the book, the program stops working.

Some things that happen: Whenever I don't render with the Geometry Shader, all of the other Shader things work with the past example. And when I take out glVertexAttrib4fv();, and I keep the geometry shader is rendered, it only renders one point. Please help. (I am using glDrawArrays(GL_POINTS,0,3);)

#version 410 core

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

void main(void)
{
    int i;
    for(i = 0; i < gl_in.length();i++)
    {
        gl_Position = gl_in[i].gl_Position;
        EmitVertex();
    }   
}
Rabbid76
  • 202,892
  • 27
  • 131
  • 174

1 Answers1

1

Let me quote from the documentation and highlight the important parts in bold.

The input_primitive​ type must match the primitive type for the vertex stream provided to the GS. If Tessellation is enabled, then the primitive type is specified by the Tessellation Evaluation Shader's output qualifiers. If Tessellation is not enabled, then the primitive type is provided by the drawing command that renders with this shader program.

Meaning the input primitive type in the geometry shader should match the type given to the draw command glDrawArrays().

Here is the matching list, check the documentation: https://www.khronos.org/opengl/wiki/Geometry_Shader

GEOMETRY INPUT: points  
DRAW COMMAND: GL_POINTS  
NUMBER OF VERTICES: 1   

GEOMETRY INPUT: lines  
DRAW COMMAND: GL_LINES or GL_LINE_STRIP or GL_LINE_LIST  
NUMBER OF VERTICES: 2

GEOMETRY INPUT: triangles  
DRAW COMMAND: GL_TRIANGLES or GL_TRIANGLE_STRIP or GL_TRIANGLE_FAN  
NUMBER OF VERTICES: 3

Where number of vertices is the number of vertices received per input primitive to the geometry shader.

Zebrafish
  • 11,682
  • 3
  • 43
  • 119
  • No, I meant for it to be like this photo (scroll down to the bottom and you will find the photo) :http://www.informit.com/articles/article.aspx?p=2429029&seqNum=4. I already have a tessellated triangle, I just need it to be changed by a geometry shader as the photo shows. To find how it looks without the geometry shader (in my code) look here :http://www.informit.com/articles/article.aspx?p=2429029&seqNum=3 – Ryanwuzhere Oct 04 '17 at 21:02
  • render method: https://www.dropbox.com/s/9ik12fw22s4iqun/render.txt?dl=0 – Ryanwuzhere Oct 04 '17 at 21:06