Return/Output variables from shader

Hello. I’ve been learning GLSL recently, however it’s difficult to debug my code without some type of output to see what is happening.

In C I usually output to a file variable values when I need to, but I haven’t been able to find a way to get the values of variables in a shader program. Is there any way to output these so I can tell what is happening in the program?

The only thing you can do to debug a shader (outside of using a shader debugger) is to write values on the screen. Your vertex shader can always return vertices directly in clip-space (which is in front of the viewer), and your fragment shader can return any value it wants.

Ok thanks. So the fragment shader can return a value to my code? That would help as I’m trying to get a handle on how depth is handled there compared to the depth handling in the code.

So the fragment shader can return a value to my code?

No. It can write values to the screen. As in colors. That’s what fragment shaders write.

When you debug a fragment shader, you use the ability to write colors to tell you something about what is going on in the shader. You can write a specific number as a color, you can write some value conditionally to test things, etc.

Ahh ok. Thanks!

The gDEBugger at can help you. You can single step drawing calls and monitor shader uniforms.