glMaterialfv with FloatBuffer

Here’s an odd problem I have at the moment with nio. I’ve pulled out the relevant lines of code here:

FloatBuffer red;
red = FloatBuffer.allocate(4);
red.put(1.0f);
red.put(0.0f);
red.put(0.0f);
red.put(1.0f);

If use this:
gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, red);                  <--- I get a black shape

Whereas if I use this:
gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, red.array(),0);  <--- I get a nice red shape

wossup wivit? I would’ve thought that the first call was just a convenience method for the second anyway…

I also get the same problem if I use red = ByteBuffer.allocateDirect(4 * Float.SIZE).asFloatBuffer()

Thanks.

Tim

Oh mama - I bet it’s byte ordering isn’t it? Although a quick play with BufferUtil didn’t help…

Tim

Did you rewind your buffer?

No, but surely rewind is only for re-writing? I can do any number of .gets();

Tim

Ahh, no. put() increments the buffer position (it’s in the docs!). You need to rewind.

And you are right, of course. Thank you, both.

Tim