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.

4
  • 1
    Are you sure it crashes because of your fragment shader? Commented May 16, 2011 at 20:38
  • 1
    What you're doing sounds ok. Where exactly is the crash occurring ? Commented May 16, 2011 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. Commented May 17, 2011 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. Commented May 19, 2011 at 16:58

1 Answer 1

2

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

in vec4 test;
Sign up to request clarification or add additional context in comments.

1 Comment

Ah sorry, that was a typo, that occured while I stripped down the code for Stackoverflow :). However one upvote for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.