From: Kenneth B. R. <kbr...@al...> - 2001-11-27 06:35:09
|
> Java doesn't have any unsigned data types, so this method dies a death > when the signed data is read as unsigned, it becomes massive and the > native code tries to read beyond the end of the array. > > Or at least thats what I think is happening. I can't find any examples > in the demos that use glDrawElements: is this because it doesn't work? http://java.sun.com/products/jfc/tsc/articles/jcanyon/ See the source code, specifically terrain.MultiResTile. Signed versus unsigned only really becomes an issue when promoting to a larger type; for example, byte to int. If the high bit is set and the type is signed (as all types are in Java) then the value will be sign-extended. In Java this is most problematic when dealing with byte and short types which automatically get promoted to ints in intermediate expressions. I frequently promote to int early, masking appropriately if necessary, and deal with ints from then on. However, when dealing with OpenGL, one can pretty much ignore the issue. You need to ensure that you are using the correct Java data type to match the one expected by OpenGL (byte for GL_UNSIGNED_BYTE, short for GL_UNSIGNED_SHORT, and int for GL_UNSIGNED_INT). Even if the values in the array overflow into the high bit (and therefore become negative in Java's view), OpenGL will treat them properly. |