read and write FloatBuffer as binary file in android

1k views Asked by At

I'm playing around with OpenGL ES 2 and FloatBuffers. Actually i try to save the FloatBuffer handling the Vertices Data to a binary file. It seems to work but after reading in the floats and puting them back togehter to a FloatBuffer the object is messed up.

For saving the float data from my Buffer i use the following code:

for(int i = 0; i < bufferSize; i++)
 outStream.writeFloat(floatBuffer.get(i));

For reading:

for(int i = 0; i < bufferSize; i++)
  if(inStream.available() != 0)
    tmpFloat[i] = inStream.readFloat();

FloatBuffers are created this way:

FloatBuffer VertexBuffer = ByteBuffer.allocateDirect(VertexFloatArray.length * mBytesPerFloat).order(ByteOrder.nativeOrder()).asFloatBuffer();
VertexBuffer.put(VertexFloatArray).position(0);

Does anyone have a idea why this happens?

UPDATE: I already compared the data written and readed and they are equal. The problem is still there and this is just more confusing.

1

There are 1 answers

0
ZeroTek On

Well, i didn't solve the problem but instead of writing just the vertexbuffer to a file i tried writing a packed buffer (containing vertex, texture coords, normals, etc) and this worked perfectly. I can't figure out why this works and a single buffer doesn't but for my needs the question is answered.