About FBO GL_COLOR_ATTACHMENTn

I was wondering why there’s more than one color attachment in a FBO. As far as I know, all the color attachments have the render result (Am I correct?).

If this is true, why not render the color buffer to one texture and use that texture multiple times?

I was wondering why there’s more than one color attachment in a FBO.

So that you can output multiple different values to multiple buffers from the same fragment shader.

Suppose I have a FBO with 2 color attachments. How, in the fragment shader, can I do this? (Never Saw a shader that does that)

Like this.

That’s the modern way to do it.

Or if forced to use an old GLSL profile (GLSL 1.2 or earlier), write to gl_FragData[n], where n is an index into the bound draw buffers. These draw buffers themselves are identified with the COLOR_ATTACHMENTn enums.

Thank you guys, this saves my life, literally.

Since I need a multi platform application (windows, linux and mac), I need to use glsl 1.2, since MacOS does not offer support for OpenGL > 2.1