Render to Framebuffer with OpenGL 3.1

I’ve been following this tutorial to try to get a simple mirror working. Since that tutorial series uses OpenGL 3.3 and I only have support up to 3.1, I had to change a few things, but not much. However, there’s a part where this line is added to the fragment shader:

layout(location = 0) out vec3 color;

Since I only have GLSL 1.3, I can’t use location=# syntax. In the past, for shader inputs I’ve just used glBindAttribLocation before linking the program, but that was only for the vertex shader, and for inputs, not outputs. How can I specify the location of a fragment shader output, with GLSL 1.3?

For fragment shader outputs you have to use glBindFragDataLocation. It works exactly how glBindAttribLocation works for vertex attributes.

And since the location is zero, you can just delete the layout and do nothing. Locations default to zero.

Ah, thanks, that appears to be want I was missing.

You mean delete the layout part in the shader? Or that I could omit that glBindFragDataLocation line entirely?

Locations default to zero.

I would love to see some confirmation on this in the OpenGL specification. I used to think that this was true until I actually looked through the spec. And I have yet to find any evidence to support it.