PDA

View Full Version : fragment shader output



Piotrek Janisz
06-07-2011, 09:24 AM
Hello,

I want to write float data from my fragment shader to texture.

fragment shader code:


#version 150
out float something;

void main(void)
{
something = 123.321;
}



That's how I initialized framebuffer and texture:


glBindFragDataLocation(myShader, 0, "something");

...

glBindTexture(GL_TEXTURE_2D, texture);
glTexImage(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, myFramebuffer);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);


However it doesn't work with this code.
Does anybody know how to do that?

Alfonse Reinheart
06-07-2011, 10:07 AM
The depth component is not a color output. It is the depth component. It is written by writing to gl_FragDepth.

Piotrek Janisz
06-07-2011, 11:35 AM
Ok, so what texture format should I use?
And I also don't want to bind texture to GL_DEPTH_ATTACHMENT.

Alfonse Reinheart
06-07-2011, 12:30 PM
A floating-point texture format that contains a single float value. Like GL_R32F (http://www.opengl.org/wiki/Image_Format).