Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (739)
Games in Android Showcase (224)
games submitted by our members
Games in WIP (820)
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 1653 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  
 
 
You cannot reply to this message, because it is very, very old.

 
Ecumene (48 views)
2017-09-30 02:57:34

theagentd (72 views)
2017-09-26 18:23:31

cybrmynd (182 views)
2017-08-02 12:28:51

cybrmynd (180 views)
2017-08-02 12:19:43

cybrmynd (187 views)
2017-08-02 12:18:09

Sralse (193 views)
2017-07-25 17:13:48

Archive (744 views)
2017-04-27 17:45:51

buddyBro (876 views)
2017-04-05 03:38:00

CopyableCougar4 (1423 views)
2017-03-24 15:39:42

theagentd (1316 views)
2017-03-24 15:32:08
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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!