Advertisement
MsXTab

Untitled

Dec 20th, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  1. package cz.sam.cubix.util;
  2.  
  3. import java.awt.Color;
  4.  
  5. import org.lwjgl.opengl.GL11;
  6.  
  7. public class ColorRGBA {
  8.    
  9.     public static ColorRGBA WHITE = new ColorRGBA(255, 255, 255);
  10.     public static ColorRGBA BLACK = new ColorRGBA(0, 0, 0);
  11.     public static ColorRGBA RED = new ColorRGBA(255, 0, 0);
  12.     public static ColorRGBA GREEN = new ColorRGBA(0, 255, 0);
  13.     public static ColorRGBA BLUE = new ColorRGBA(0, 0, 255);
  14.    
  15.     private int red;
  16.     private int green;
  17.     private int blue;
  18.     private int alpha;
  19.    
  20.     public ColorRGBA(int color) {
  21.         this.red = color >> 16 & 255;
  22.         this.blue = color >> 8 & 255;
  23.         this.green = color & 255;
  24.         this.alpha = color >> 24 & 255;
  25.     }
  26.    
  27.     public ColorRGBA(int red, int green, int blue, int alpha) {
  28.         this.red = red;
  29.         this.green = green;
  30.         this.blue = blue;
  31.         this.alpha = alpha;
  32.        
  33.         if(this.red > 255) this.red = 255;
  34.         if(this.green > 255) this.green = 255;
  35.         if(this.blue > 255) this.blue = 255;
  36.         if(this.alpha > 255) this.alpha = 255;
  37.        
  38.         if(this.red < 0) this.red = 0;
  39.         if(this.green < 0) this.green = 0;
  40.         if(this.blue < 0) this.blue = 0;
  41.         if(this.alpha < 0) this.alpha = 0;
  42.     }
  43.    
  44.     public ColorRGBA(int red, int green, int blue) {
  45.         this(red, green, blue, 255);
  46.     }
  47.    
  48.     public ColorRGBA(float red, float green, float blue) {
  49.         this((int)red * 255, (int)green * 255, (int)blue * 255, 255);
  50.     }
  51.    
  52.     public ColorRGBA(float red, float green, float blue, float alpha) {
  53.         this((int)red * 255, (int)green * 255, (int)blue * 255, (int)alpha * 255);
  54.     }
  55.    
  56.     public Color getAWTColor() {
  57.         return new Color(this.red, this.green, this.blue, this.alpha);
  58.     }
  59.    
  60.     public void bind() {
  61.         GL11.glColor4f(this.red / 255F, this.green / 255F, this.blue / 255F, this.alpha / 255F);
  62.     }
  63.  
  64.     public int getRed() {
  65.         return red;
  66.     }
  67.  
  68.     public int getGreen() {
  69.         return green;
  70.     }
  71.  
  72.     public int getBlue() {
  73.         return blue;
  74.     }
  75.  
  76.     public int getAlpha() {
  77.         return alpha;
  78.     }
  79.    
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement