LWJGL
May 22, 2013, 04:39:58 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL 2.9.0 released!
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: Rendering FBO to image gives wrong color values.  (Read 746 times)
sasmaster
Newbie
*
Posts: 13


« on: June 07, 2012, 07: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?
Logged
Fool Running
Nerdus Imperius
*****
Posts: 742


« Reply #1 on: June 08, 2012, 05: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:
Code:
((_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:
Code:
_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).
Logged

Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option Grin
abcdef
Regular nerd
**
Posts: 82


« Reply #2 on: June 08, 2012, 06:50:38 »

To convert to the values you'd expect do

int myint = (int)mybyte & 0xff

Logged
sasmaster
Newbie
*
Posts: 13


« Reply #3 on: June 08, 2012, 07:01:05 »

Thanks guys for the input .Actually my bitwise expressions were wrong Tongue   
Here is how it should be :
Code:

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

Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!