LWJGL
May 20, 2012, 23:31:39 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

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



Pages: [1]
  Print  
Author Topic: BumpMap Inversion Problem  (Read 4167 times)
xindon
Newbie
*
Posts: 32



WWW
« on: June 17, 2006, 07:16:49 »

Hey,
I'm trying to load a bumpmap image and invert it by subtracting a byte's value from 255.
The image data is stored in a ByteBuffer. When I try to access the bytes I get some strange results. For example -103. I think there should only be values from 0 to 255 ?
Are they unsigned bytes? What am I doing wrong?

Thank you very much...
and sorry for my bad English {grin}


Code:

        ByteBuffer imageData = null;
        IntBuffer tmp = BufferUtils.createIntBuffer(1);

        IL.ilGenImages(tmp);
        IL.ilBindImage(tmp.get(0));

        IL.ilLoadImage(path);

        IL.ilConvertImage(IL.IL_RGB, IL.IL_BYTE);

        imageData = IL.ilGetData();

        System.out.println(imageData.get(0));  // Output:  -103


        /* create texture in opengl....*/
        GL11.glGenTextures(tmp);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, tmp.get(0));
        .....
Logged

ggp83
Newbie
*
Posts: 6


« Reply #1 on: June 18, 2006, 13:37:27 »

A byte in Java ranges from -128 to +127. So a Java byte is not unsigned but signed. To get values above 127, you'll have to cast the byte to a type which can hold larger numbers, such as a short. However just casting it will make it stay negative, so you'll have to make some "addition", like this:

Code:

byte b = (byte)203; // turns into -53

// convert to short
short s = b<0?(short)(256 - (-b)):b; // s now contains 203


edit. Should probably say that I'm not the most experienced programmer in Java, so there might be a nicer/better way to do this.
Logged
spasi
Nerdus Imperius
*****
Posts: 643



WWW
« Reply #2 on: June 19, 2006, 01:41:36 »

This one is faster:

Code:
int ub = b & 0xFF
Logged

xindon
Newbie
*
Posts: 32



WWW
« Reply #3 on: June 19, 2006, 10:46:21 »

I need the pixel's color values. These range from 0 (no intensity) to 255 (full intensity).
So does -128 (byte) stand for 0 and 127 (byte) for 255 ?

Thanks
Logged

ggp83
Newbie
*
Posts: 6


« Reply #4 on: June 19, 2006, 19:18:47 »

No, -128 is 255, -127 is 254 and -1 is 128.
Logged
Pages: [1]
  Print  
 
Jump to:  

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