Pass org.lwjgl.util.Color to glUniform4

Started by oglun, August 17, 2011, 08:15:59

Previous topic - Next topic

oglun

I have a shader with a uniform for a color. The glUnitform4 Method takes a FloatBuffer or an IntBuffer as parameter.
Naturally I would like to use the org.lwjgl.util.Color to represent my color but I encountered some strange things: The color class can write it's information to a ByteBuffer which then could be "casted" to a FloatBuffer with asFloatBuffer But this doesn't work because the byte color values are not masked. If you won't to the color object as FloatBuffer you have to do something like this:
val color = new Color(255, 0, 0, 255)
val buffer = BufferUtils.createFloatBuffer(4)
buffer.put(color.getRed())
buffer.put(color.getGreen())
buffer.put(color.getBlue())
buffer.put(color.getAlpha())
buffer.flip()


But this is a little bit tedious, so my question is: Isn't there a method on Color I missed? Or is this somehow a better way?

Site note: it seems that the color class has some API inconsistencies with the rest of the util. e.g. the methods to write the data to a buffer are writeXXX and not store like the vector class. Likewise, this methods don't return an instance to itself like the vector does in store