direct FloatBuffer problem

I’ve just recently decided to start using lwjgl instead of jogl and I seem to have run into a bit of a problem. I created a simple scene with some rotating cubes and such and everything works fine… until I try adding a light. I keep getting the error:

java.lang.IllegalArgumentException: FloatBuffer is not direct

when I call:

GL11.glLight(GL11.GL_LIGHT0, GL11.GL_AMBIENT, ltAmbeint);

I’m creating ltAmbient like this:

float[] ambientValues = new float[]{.2f, .2f, .2f, 1.0f};

FloatBuffer ltAmbient= ByteBuffer.allocateDirect(16).order(ByteOrder.nativeOrder()).asFloatBuffer();
ltAmbient.put(ambientValues).flip();

I’ve looked at a couple other examples which seem to be doing this pretty much exactly the same and it appears to work. Any idea why my FloatBuffer isn’t direct? The code shown above is contained in my initGL() method which gets called immediately after the display is created.

crap, this was a stupid error (and I spent so long on it :-/ ) I was creating the FloatBuffer in a different way earlier and I was getting the error I posted, I then changed it to the code you see and the error persisted. What I didn’t notice was that the error was now coming from a new line number where the old code hadn’t changed :frowning: ah well, its working now.

You may find using the org.lwjgl.BufferUtils class helpful.