LWJGL Forum

Programming => OpenGL => Topic started by: dunno on December 15, 2009, 05:52:25

Title: How to obtain current color?
Post by: dunno on December 15, 2009, 05:52:25
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.
Title: Re: How to obtain current color?
Post by: Kai on December 15, 2009, 10:03:00
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)?
Title: Re: How to obtain current color?
Post by: dunno on December 15, 2009, 11:02:04
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 ?
Title: Re: How to obtain current color?
Post by: dunno on December 15, 2009, 11:34:36
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)?
Title: Re: How to obtain current color?
Post by: broumbroum on December 15, 2009, 15:49:10
you only read the 3 or 4 first entries, other entries are left empty.
Title: Re: How to obtain current color?
Post by: dunno on December 15, 2009, 21:53:28
Thanks a lot, everything seems to work properly now.