glGetFloat usage

Started by Whackjack, October 28, 2005, 13:53:27

Previous topic - Next topic

Whackjack

I'm trying to get the current color (GL_CURRENT_COLOR) so I can restore it after I make a change.  I passed in the flag and a FloatBuffer, then ran it.  Here's what I got:

java.lang.IllegalArgumentException: Number of remaining buffer elements is 4, must be at least 16
   at org.lwjgl.BufferChecks.checkBufferSize(BufferChecks.java:177)
   at org.lwjgl.BufferChecks.checkBuffer(BufferChecks.java:197)
   at org.lwjgl.opengl.GL11.glGetFloat(GL11.java:1155)

I assumed that since the color is defined by 4 elements, that's all I would need.  Why 16?  And if there are that many elements, how do I know which ones to get at for each RGBA value?

Matzon

you need 16, coz thats what we check for as minimum size - even though you only use 4

Whackjack

Okay... So, I can call FloatBuffer.get() 4 times and I'll get the values I need?  What is put into the rest of this buffer?  Whatever's left over in memory?

On a side note, I found a better way of restoring the previous color.

GL11.glPushAttrib(GL11.GL_CURRENT_BIT);
// do stuff here
GL11.glPopAttrib();

This seems to work perfectly.  OpenGL Blue Book saves the day!

Thanks for you input, Matzon.

Matzon

no, you pass in a buffer with at least 16 elements, and the first 4 are populated.

We always use buffers of 16 since thats what most methods expect and thus simplifies error checking greatly.