Вопрос

At this point I have a working vertex and fragment shader. If I remove my geometry shader completely, then I get the expected cube with colors at each vertex. But with the geometry shader added, no geometry shows up at all.

Vertex Shader:

#version 330 core

layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec3 vertexColor;

out VertexData
{
    vec3 color;
} vertex;

uniform mat4 MVP;

void main(){    

    gl_Position =  MVP * vec4(vertexPosition_modelspace,1); 
    vertex.color = vertexColor;
}

Geometry Shader:

#version 330

precision highp float;

in VertexData
{
    vec3 color;
} vertex[];

out vec3 fragmentColor;

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

void main(void)
{
    for (int i = 0; i > gl_in.length(); i++) {

        gl_Position = gl_in[i].gl_Position;
        fragmentColor = vertex[i].color;
        EmitVertex();
    }

    EndPrimitive();
}

Fragment Shader:

#version 330 core

in vec3 fragmentColor;

out vec3 color;

void main(){
    color = fragmentColor; 
}

My graphics card supports OpenGL 3.3 from what I can tell. And, as I said. It works without the Geometry shader. As data, I am passing in two arrays of GLfloat's where each is a vertex or a vertex color respective.

Это было полезно?

Решение

for (int i = 0; i > gl_in.length(); i++)   //note the '>'

This loop condition will be false right from the start, so you won't ever emit any vertices. What you most probably meant is i < gl_in.length().

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top