Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (767)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (854)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  ByteBuffer issue  (Read 1861 times)
0 Members and 1 Guest are viewing this topic.
Offline numknuf

Senior Newbie




bompi


« Posted 2008-01-11 15:57:19 »

I am doing something like this:


ByteBuffer buffer = Bufferutil.newByteBuffer(size);

buffer.putShort(s);
...

glTexSubImage3D(GL.GL_TEXTURE_3D, 0, 0, 0, 0, w, h, d, GL.GL_ALPHA, GL.GL_Short, buffer.asShortBuffer());


But the results I'm getting looks like there is a problem with endianness.

Anyone see anything wrong with this approach?
Offline numknuf

Senior Newbie




bompi


« Reply #1 - Posted 2008-01-11 16:14:16 »

When I use putFloat(f), GL_FLOAT and buffer.asFloatBuffer() the program works as expected...
Offline jwatte

Senior Newbie





« Reply #2 - Posted 2008-01-12 02:58:31 »

Try calling order(ByteBuffer.nativeOrder()) on the ByteBuffer after you create it, before you write anything.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline lhkbob

JGO Knight


Medals: 32



« Reply #3 - Posted 2008-01-12 03:54:44 »

Try using ShortBuffer buffer = BufferUtil.newShortBuffer(), then buffer.put(...short value...) and in the gl call just use buffer.
Pretty sure BufferUtil lets you create a short buffer as well.  I doubt this will change anything but just in case.

Offline numknuf

Senior Newbie




bompi


« Reply #4 - Posted 2008-01-12 08:19:14 »

Try calling order(ByteBuffer.nativeOrder()) on the ByteBuffer after you create it, before you write anything.

This did not change anything. Sad

Try using ShortBuffer buffer = BufferUtil.newShortBuffer(), then buffer.put(...short value...) and in the gl call just use buffer.
Pretty sure BufferUtil lets you create a short buffer as well.  I doubt this will change anything but just in case.

I copied the values from my bytebuffer to a shortbuffer but I got the same results. But I need to have a bytebuffer so that the class can support both bytes and floats as well.


I am also sure that the buffers contain correct values before being sent to OpenGL.
Offline numknuf

Senior Newbie




bompi


« Reply #5 - Posted 2008-01-12 09:18:07 »

I just found out that the problem is not endianness but something related to:

scale = 1.0f / (maxValue - minValue); //max = 4080, min = 0
gl.glPixelTransferf(GL.GL_ALPHA_SCALE, scale);

When using GL_FLOAT this works as expected. But with GL_SHORT the scale must be something like 5 to represent a useable range.

What am I doing wrong?
Offline numknuf

Senior Newbie




bompi


« Reply #6 - Posted 2008-01-12 10:34:47 »

Looks like this is my issue:

Quote
GL_RGBA
Each pixel is a four-component group: for GL_RGBA, the red component is first, followed by green, followed by blue, followed by alpha. Floating-point values are converted directly to an internal floating-point format with unspecified precision. Signed integer values are mapped linearly to the internal floating-point format such that the most positive representable integer value maps to 1.0, and the most negative representable value maps to -1.0. (Note that this mapping does not convert 0 precisely to 0.0.) Unsigned integer data is mapped similarly: the largest integer value maps to 1.0, and 0 maps to 0.0. The resulting floating-point color values are then multiplied by GL_c_SCALE and added to GL_c_BIAS, where c is RED, GREEN, BLUE, and ALPHA for the respective color components.

From: http://developer.3dlabs.com/documents/GLmanpages/glteximage3dext.htm
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (1303 views)
2018-06-10 19:43:48

EgonOlsen (1161 views)
2018-06-10 19:43:44

EgonOlsen (900 views)
2018-06-10 19:43:20

DesertCoockie (1301 views)
2018-05-13 18:23:11

nelsongames (1106 views)
2018-04-24 18:15:36

nelsongames (1338 views)
2018-04-24 18:14:32

ivj94 (2080 views)
2018-03-24 14:47:39

ivj94 (1231 views)
2018-03-24 14:46:31

ivj94 (2214 views)
2018-03-24 14:43:53

Solater (798 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!