Uninitialized variable in shader tutorial blur example

The example blur shader didn’t work for me until I added a line to initialize the color variable in the shadersGL3/ .frag files:

vec4 color; // apparently on my machine this variable starts its life full of garbage,
color= vec4(0,0,0,0); // so I added this line and all became well

Hi there!

From my experience, openGL/GLSL can be really picky. Not only you get different results/errors if you’re working on GL or GLES, but also in major, minor versions and also depending on the GPU that you have.

As an example, in GLES, once I had a shader working on GL but not on GLES, simply because I was assigning a variable as vec4(0) and not vec4(0.0).

So in your case, I think it’s not a bug, per se. But it’s a good method to always assign and work with floats.

Oops, I do usually remember not to type my floats as ints. I guess color= vec4(0.0, 0.0, 0.0, 0.0); would be better. Thanks.
Could adding an initialization line possibly break things
for someone else? I assumed it was just an oversight that happened to
not be a problem on the author’s GPU, hence the post. Granted, anyone
actually following the tutorial and not just trying to grab a quick blur
shader (don’t look at me) should probably be able to figure stuff like
that out. Not a big deal in any case.