3

I have an GLSL geometry shader that looks like the following:

#version 150

uniform mat4 p;
uniform mat4 mv;
uniform mat3 nm;

layout(points) in;
layout(triangle_strip, max_vertices = 200) out;

out vec4 test;

void main() {
    for (int i = 0; i < gl_in.length(); i++) {
        ....        
        gl_Position = p * mv * gl_in[i].gl_Position;
        test = vec4(1.0, 0.0, 0.0, 0.0);
        EmitVertex();       
        ....        
        EndPrimitive();
    }
}

However when I try to access "test" in my fragment shader my application crashes. Here is my fragment shader:

#version 150

out vec4 fColor;
in vec4 test;

void main(void) {
    fColor = vec4(test.x, 1.0, 0.4, 0);
}

Can someone help me to pass a variable from the geometry to the fragment shader? varying is deprecated in #version 150.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
iuiz
  • 957
  • 1
  • 10
  • 23
  • 1
    Are you sure it crashes because of your fragment shader? – Christian Rau May 16 '11 at 20:38
  • 1
    What you're doing sounds ok. Where exactly is the crash occurring ? – Nicolas Lefebvre May 16 '11 at 20:50
  • Im using JOGL2, because I am writing this application in Java. If the shader looks right to you it realy helps me a lot, because then the bug might be somewhere else. I don't even get a response from the GPU, so I think this might be a bug in the Java OpenGl bindings... I currently don't know which code part I should post, because I am not sure wether it helps or not... I will update my post if I know more. Thx for the help. – iuiz May 17 '11 at 18:21
  • 1
    Try commenting out `test`, and writing `fColor = vec4(1.0);`. If that works, `test` *might* be the problem, otherwise you can rule it out. – UncleZeiv May 19 '11 at 16:58

1 Answers1

2

You need to declare test as input in your fragment shader (I wonder why the shader compiles):

in vec4 test;
Christian Rau
  • 45,360
  • 10
  • 108
  • 185
  • Ah sorry, that was a typo, that occured while I stripped down the code for Stackoverflow :). However one upvote for you. – iuiz May 16 '11 at 20:23