PDA

View Full Version : Render to Framebuffer with OpenGL 3.1



fiodis
08-02-2013, 10:59 AM
Hello,
I've been following this (http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-14-render-to-texture/) 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?

aqnuep
08-02-2013, 11:37 AM
For fragment shader outputs you have to use glBindFragDataLocation. It works exactly how glBindAttribLocation works for vertex attributes.

arekkusu
08-02-2013, 12:34 PM
And since the location is zero, you can just delete the layout and do nothing. Locations default to zero.

fiodis
08-02-2013, 01:38 PM
For fragment shader outputs you have to use glBindFragDataLocation. It works exactly how glBindAttribLocation works for vertex attributes.
Ah, thanks, that appears to be want I was missing.

And since the location is zero, you can just delete the layout and do nothing. Locations default to zero.
You mean delete the layout part in the shader? Or that I could omit that glBindFragDataLocation line entirely?

Alfonse Reinheart
08-02-2013, 01:54 PM
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.