wrongu
wrongu

Reputation: 580

ByteBuffer.allocateDirect().asFloatBuffer() vs BufferUtils.createFloatBuffer()

I just solved a bug and I'm not sure why. Creating a 4x4 projection matrix in LWJGL, for use in a vertex shader..

This line causes problems. It fails silently and my mat4 in the shader is stuck as all zeros (as if it was never written).

FloatBuffer mProj = ByteBuffer.allocate(4*16).asFloatBuffer();

This works as expected.

FloatBuffer mProj = BufferUtils.createFloatBuffer(16);

As a sanity-check, I confirmed that my floats are 4 bytes. So what's the difference?

Upvotes: 0

Views: 779

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 280011

The only difference between those two is possibly the byte order. You can set it as

FloatBuffer mProj = ByteBuffer.allocate(4 * 16).order(ByteOrder.nativeOrder()).asFloatBuffer();

Upvotes: 3

Related Questions