I made this class a long time ago, and it still works. I thought you guy’s may need a well-documented color object for whatever.
Feel free to credit me, or just remove the name. Its not like its protected or anything
*Please just reply with any constructive criticism
package passage.blu.data;
import org.lwjgl.opengl.GL11;
/**
* A class containing color specific data
* like red, green, blue, and alpha transparency.
*
* @author Mitchell Hynes (Spacebeans)
*/
public class Color {
public float r, g, b, a;
/**
* Constructs a color from red, green, blue, and alpha values.
*
* @param red The red hue
* @param green The green hue
* @param blue The blue hue
* @param alpha The alpha transparency
*/
public Color(float red, float green, float blue, float alpha){
r = red; g = green; b = blue; a = alpha;
}
/**
* Constructs a color from red, green, and blue values, with full alpha
*
* @param red The red hue
* @param green The green hue
* @param blue The blue hue
*/
public Color(float red, float green, float blue){
this(red, green, blue, 255);
}
/**
* Sets the colors values
*
* @param r Red value (255)
* @param g Green value (255)
* @param b Blue value (255)
* @param a Alpha value (255) - Transparency
*/
public void set(float r, float g, float b, float a){
this.r = r; this.g = g; this.b = b; this.a = a;
}
/**
* Gets all the values divided by the maximum color value.
* (255)
*
* Mostly used in OpenGL bindings
*
* @return All the color values divided by the maximum color value.
*/
public Color getAsFloat(){
return new Color(r/255, g/255, b/255, a/255);
}
/**
* Binds the color (glColor3f)
*/
public void bind(){
GL11.glColor4f(r, g, b, a);
}
/**
* Resets OpenGL's current color to full
* red, green, blue, and alpha.
*/
public static void resetColors(){
GL11.glColor4f(1, 1, 1, 1);
}
/**
* @return The red color component
*/
public float getRed() {
return r;
}
/**
* @param r The red component to set
*/
public void setRed(float r) {
this.r = r;
}
/**
* @return The green color component
*/
public float getGreen() {
return g;
}
/**
* @param g The green component to set
*/
public void setGreen(float g) {
this.g = g;
}
/**
* @return The blue color component
*/
public float getBlue() {
return b;
}
/**
* @param b The blue component to set
*/
public void setBlue(float b) {
this.b = b;
}
/**
* @return The alpha component
*/
public float getAlpha() {
return a;
}
/**
* @param a The alpha color component to set
*/
public void setAlpha(float a) {
this.a = a;
}
}