Java tutorial
/** * Copyright (c) Lambda Innovation, 2013-2015 * ??Lambda Innovation * http://www.li-dev.cn/ * * This project is open-source, and it is distributed under * the terms of GNU General Public License. You can modify * and distribute freely as long as you follow the license. * ??GNU??? * ???? * http://www.gnu.org/licenses/gpl.html */ package cn.liutils.cgui.utils; import org.lwjgl.opengl.GL11; /** * @author WeAthFolD */ public class Color { public double r, g, b, a; public Color(double _r, double _g, double _b, double _a) { setColor4d(_r, _g, _b, _a); } public Color() { this(1, 1, 1, 1); } public Color(int hex) { fromHexColor(hex); } public void setColor4i(int r, int g, int b, int a) { setColor4d(r / 255.0, g / 255.0, b / 255.0, a / 255.0); } public void setColor4d(double _r, double _g, double _b, double _a) { r = _r; g = _g; b = _b; a = _a; } public void fromHexColor(int hex) { setColor4i(hex & 0xFF, (hex >> 8) & 0xFF, (hex >> 16) & 0xFF, (hex >> 24) & 0xFF); } public int asHexColor() { byte ir = (byte) (r * 255), ig = (byte) (g * 255), ib = (byte) (b * 255), ia = (byte) (a * 255); ; return ir | ig << 8 | ib << 16 | ia << 24; } public void bind() { GL11.glColor4d(r, g, b, a); } public Color copy() { return new Color(r, g, b, a); } public String toString() { return String.valueOf(asHexColor()); } public static Color WHITE = new Color(1, 1, 1, 1); }