Rendering FBO to image gives wrong color values.

Started by sasmaster, June 07, 2012, 14:44:19

Previous topic - Next topic

sasmaster

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?

Fool Running

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).
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

abcdef

To convert to the values you'd expect do

int myint = (int)mybyte & 0xff


sasmaster

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