# How to debug a GLSL shader? [duplicate]

I cannot find any tutorial in Google and Youtube. I have a C++ program that uses OpenGL ES 2.0 API to render something on the screen. How can I debug my shaders? Any step-by-step guide? What is the easiest way to at least print variable values?

• gamedev.stackexchange.com/questions/34392/… – MichaelHouse Jun 22 '15 at 14:52
• @Byte56 this is not a duplicate. In your link there is not step by step tutorial. – Narek Jun 22 '15 at 19:39
• Why would the question have a step-by-step tutorial? Remember that questions are duplicated, not the answers they contain. – MichaelHouse Jun 22 '15 at 19:44

In general, you can't. The typical development environments only give you visibility on the C/C++ side.

So, I say "you can't" but that's obviously not exactly true. You can't step through the shader and print variables, but still we all develop and debug shaders. But it's a lot of intuiting indirectly what's going on, by repeated runs. Some of the things I do is:

• Have a simplified version of my app that only draws 1 or 2 things, so try/edit/retry goes faster
• Have a few fallback shaders that I know work, and swap them in when I'm doubting my own sanity...
• Use revision control, of course
• Always print out all the error messages from compiling with glGetShaderInfoLog()

In some game engine environments, you author shaders at a higher level, using flow diagrams and such, and the engine generates GLSL (or HLSL &c) on the fly, which is a whole different debug experience.

Hope that helps!

• The answers to the duplicate question mention step-debugging tools for shaders. – Philipp Jun 22 '15 at 15:10