Hi again. I notice in my fragment shader if i return the value of 9.0 i get 9.0 in my texture that reads from FBO. If i return a texture that i had input in Fragment shader i get values clamped between 0-1.
This is the setup of input texture:
glBindTexture(GL_TEXTURE_2D, texName);
//Settng Parameters for texture
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
//Moving data to Texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F_ARB, size, size, 0, GL_RED, GL_UNSIGNED_BYTE, texPtr);
char errormsg[50];
sprintf(errormsg,"Error creating or Binding texture: %s ",textureName);
checkGLErrors(errormsg);
If i print in a file the buffer array i get normal vvalues betwwen 0-16bit
glGenTextures( 1, &texture1 );
init2DTexture("texture1",texture1,size,size,buffer);
free(buffer);
And this is the whole output texture creation and fbo rendering:
//Setup output texture
GLuint img;
glGenTextures(1, &img);
glBindTexture(GL_TEXTURE_2D, img);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F_ARB, size, size, 0, GL_RED, GL_UNSIGNED_BYTE, NULL);
glTexSubImage2D(GL_TEXTURE_2D,0,0,0,size,size,GL_RED,GL_FLOAT,data);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, img, 0);
checkFramebufferStatus();
checkGLErrors("Output Texture Creation");
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
checkGLErrors("Frame Buffer binding");
checkFramebufferStatus();
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
glClearColor( 0.0f, 0.0f, 0.2f, 1.0f );
glPolygonMode(GL_FRONT, GL_FILL);
glBegin( GL_QUADS );
glTexCoord2f(0.0, 1.0);
glVertex2f(0.0, 0.0);
glTexCoord2f(1.0, 1.0);
glVertex2f(size, 0.0);
glTexCoord2f(1.0, 0.0);
glVertex2f(size, size);
glTexCoord2f(0.0, 0.0);
glVertex2f(0.0, size);
glEnd();
checkFramebufferStatus();
checkGLErrors("Render to FBO");
//Reading values from frameBuffer to array with flaots
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
glReadPixels(0, 0, size, size,GL_RED,GL_FLOAT,pixels);
I know its tiring. But i am sure there must be a normal way to get the right values back. Or is there a way to transform the clamped ones i got back, into normal ?