Reputation: 1090
Code:
FloatBuffer buf = BufferTools.reserveData(4);
float[] fl = new float[]{0.1f, 0.1f, 0.1f, 1.0f};
buf.put(fl);
where buf.put(fl)
is line 2039 that the error is talking about:
Exception in thread "main" java.lang.IllegalArgumentException: Number of remaining buffer elements is 0, must be at least 4. Because at most 4 elements can be returned, a buffer with at least 4 elements is required, regardless of actual returned element count
at org.lwjgl.BufferChecks.throwBufferSizeException(BufferChecks.java:162)
at org.lwjgl.BufferChecks.checkBufferSize(BufferChecks.java:189)
at org.lwjgl.BufferChecks.checkBuffer(BufferChecks.java:258)
at org.lwjgl.opengl.GL11.glLight(GL11.java:2039)
at Joehot200.TerrainDemo.setUpLighting(TerrainDemo.java:1543)
at Joehot200.TerrainDemo.enterGameLoop(TerrainDemo.java:1984)
at Joehot200.TerrainDemo.startGame(TerrainDemo.java:2109)
at Joehot200.Main.main(Main.java:56)
What am I doing wrong? I would just like to have a FloatBuffer with 4 elements in it so that I can set the OpenGL ambient lighting.
Upvotes: 0
Views: 151
Reputation: 2877
LWJGL throws this error it the buffer is too small for the requested operation. See here
My guess is that BufferTools.reserveData(4)
reserves 4 byte and not 4*sizeof(float) == 16 byte.
Upvotes: 1