LWJGL Forum

Programming => OpenGL => Topic started by: sasmaster on June 07, 2012, 14:44:19

Title: Rendering FBO to image gives wrong color values.
Post by: sasmaster on June 07, 2012, 14:44:19
Hi All, need help here. I am rendering to image pixel data taken from FBO .The pixels values in the resulting image become half of those defined in the
fragment shader. So if the fragment outputs vec4(1.0f,0.0f,0.0f,1.0f) which should be red ,it becomes white .But if I change it to vec4(0.5,0.0f,0.0f,1.0f); then it is rendered red as supposed to be with 1.0f .
Here is my code:


What do I do wrong here?
Title: Re: Rendering FBO to image gives wrong color values.
Post by: Fool Running on June 08, 2012, 12:41:32
I think (i.e. I'm not 100% sure), that when you cast a Java byte to an int, it becomes a signed int (-127 to 128 or something). This would mean that this:
((_data.get(bindex)<<16) )    + ((_data.get(bindex+1) << 8) )  +((_data.get(bindex+2)<<0 ) )
is not quite what you need since you need to get the byte in the range of 0 to 255 before doing the bit shifting.

Also, this might be related to your problem:
_data = ByteBuffer.allocateDirect(500    * 500 * 3).order(ByteOrder.LITTLE_ENDIAN);//.order(ByteOrder.LITTLE_ENDIAN).asIntBuffer();
probably should be have .order(ByteOrder.nativeOrder()) instead (or use the BufferUtils method to create the buffer).
Title: Re: Rendering FBO to image gives wrong color values.
Post by: abcdef on June 08, 2012, 13:50:38
To convert to the values you'd expect do

int myint = (int)mybyte & 0xff

Title: Re: Rendering FBO to image gives wrong color values.
Post by: sasmaster on June 08, 2012, 14:01:05
Thanks guys for the input .Actually my bitwise expressions were wrong :P   
Here is how it should be :


pixels[i] =
                                                                // A
((_data.get(bindex) & 0x0000FF) << 16)       // R
| ((_data.get(bindex+1) & 0x0000FF) << 8)    // G
| ((_data.get(bindex+2) & 0x0000FF) << 0);   // B