Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cz.sam.cubix.util;
- import java.awt.Color;
- import org.lwjgl.opengl.GL11;
- public class ColorRGBA {
- public static ColorRGBA WHITE = new ColorRGBA(255, 255, 255);
- public static ColorRGBA BLACK = new ColorRGBA(0, 0, 0);
- public static ColorRGBA RED = new ColorRGBA(255, 0, 0);
- public static ColorRGBA GREEN = new ColorRGBA(0, 255, 0);
- public static ColorRGBA BLUE = new ColorRGBA(0, 0, 255);
- private int red;
- private int green;
- private int blue;
- private int alpha;
- public ColorRGBA(int color) {
- this.red = color >> 16 & 255;
- this.blue = color >> 8 & 255;
- this.green = color & 255;
- this.alpha = color >> 24 & 255;
- }
- public ColorRGBA(int red, int green, int blue, int alpha) {
- this.red = red;
- this.green = green;
- this.blue = blue;
- this.alpha = alpha;
- if(this.red > 255) this.red = 255;
- if(this.green > 255) this.green = 255;
- if(this.blue > 255) this.blue = 255;
- if(this.alpha > 255) this.alpha = 255;
- if(this.red < 0) this.red = 0;
- if(this.green < 0) this.green = 0;
- if(this.blue < 0) this.blue = 0;
- if(this.alpha < 0) this.alpha = 0;
- }
- public ColorRGBA(int red, int green, int blue) {
- this(red, green, blue, 255);
- }
- public ColorRGBA(float red, float green, float blue) {
- this((int)red * 255, (int)green * 255, (int)blue * 255, 255);
- }
- public ColorRGBA(float red, float green, float blue, float alpha) {
- this((int)red * 255, (int)green * 255, (int)blue * 255, (int)alpha * 255);
- }
- public Color getAWTColor() {
- return new Color(this.red, this.green, this.blue, this.alpha);
- }
- public void bind() {
- GL11.glColor4f(this.red / 255F, this.green / 255F, this.blue / 255F, this.alpha / 255F);
- }
- public int getRed() {
- return red;
- }
- public int getGreen() {
- return green;
- }
- public int getBlue() {
- return blue;
- }
- public int getAlpha() {
- return alpha;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement