How to obtain current color?

Started by dunno, December 15, 2009, 05:52:25

Previous topic - Next topic

dunno

Hello all.
suppose I set the drawing color to red using a usual command like this:
GL11.glColor(1,0,0);

How can I get this color?

I read about glGetFloat command but I dont understand how its working.
It takes two arguments: what is the first argument I must use? GL_CURRENT_COLOR?
And the second argument: it is a FoatBuffer, ok. I create it like that:
FloatBuffer color = FloatBuffer.allocate(16); (16, because I receive an error, when I use a less number)

and then call that command:
GL11.glGetFloat(GL11.GL_CURRENT_COLOR, color); - nothing happened with the variable color (it didn't change)
GL11.glGetFloat(GL11.GL_COLOR_MATERIAL, color); - nothing happened
GL_COLOR_INDEXES, GL_COLOR_MATERIAL_PARAMETER, and so on - nothing happened.
So, how to use this command?

Thanks in advance.

Kai

Hi,

that is strange.
I tried to reproduce the behaviour that you described, but when doing the following everything worked as expected:
FloatBuffer color = FloatBuffer.allocate(16);
GL11.glGetFloat(GL11.GL_CURRENT_COLOR, color);


Do you do anything else with the FloatBuffer before calling glGetFloat?
And do you call glGetFloat inside a glBegin/glEnd-block (which is not allowed)?

dunno

Kai,

No, I wrote just the same code. I mean when I run such code:
FloatBuffer color = FloatBuffer.allocate(16);
GL11.glColor(1,0,0);
GL11.glGetFloat(GL11.GL_CURRENT_COLOR, color);

in debug mode and watch the variable color, I see that color doesn't change after GL11.glGetFloat(GL11.GL_CURRENT_COLOR, color);

Quoteeverything worked as expected
And what was expected? I thought FloatBuffer color to be filled with the numbers representing current color in some way or smth like that, but it contains 16 zeros as it was after allocate command. Maybe I just misunderstand the functionality of glGetFloat ?

dunno

Oh, please, forget it, my bad. I really used it inside glBegin/glEnd, I didn't notice it from begin :)
The last question: what format of current color (suppose its RGB - three numbers) in FloatBuffer (which contains 16 numbers)?

broumbroum

you only read the 3 or 4 first entries, other entries are left empty.

dunno

Thanks a lot, everything seems to work properly now.