Mercurial > projects > mde
comparison mde/types/Colour.d @ 63:66d555da083e
Moved many modules/packages to better reflect usage.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Fri, 27 Jun 2008 18:35:33 +0100 |
parents | mde/types/basic.d@9e1f05fbbcef |
children | b525ff28774b |
comparison
equal
deleted
inserted
replaced
62:960206198cbd | 63:66d555da083e |
---|---|
1 /* LICENSE BLOCK | |
2 Part of mde: a Modular D game-oriented Engine | |
3 Copyright © 2007-2008 Diggory Hardy | |
4 | |
5 This program is free software: you can redistribute it and/or modify it under the terms | |
6 of the GNU General Public License as published by the Free Software Foundation, either | |
7 version 2 of the License, or (at your option) any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | |
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
11 See the GNU General Public License for more details. | |
12 | |
13 You should have received a copy of the GNU General Public License | |
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
15 | |
16 /** Contains a basic colour type. */ | |
17 module mde.types.Colour; | |
18 | |
19 /// Represent a colour using clamped floats | |
20 struct Colour { | |
21 /// Returns GL_ONE if total value is nearer white than black, else GL_ZERO. | |
22 uint nearestGLConst () { | |
23 return r+g+b >= 1.5f ? 1u : 0u; | |
24 } | |
25 | |
26 float r,g,b; /// values | |
27 | |
28 static { | |
29 /// Predefined colours | |
30 const Colour WHITE = { r:1f, g:1f, b:1f }; | |
31 const Colour BLACK = { r:0f, g:0f, b:0f }; /// ditto | |
32 | |
33 /// Construct from floats (doesn't clamp, but GL does when values are passed) | |
34 Colour opCall (float r, float g, float b) { | |
35 Colour c; | |
36 c.r = r; | |
37 c.g = g; | |
38 c.b = b; | |
39 return c; | |
40 } | |
41 /// Construct from ubytes | |
42 Colour opCall (ubyte r, ubyte g, ubyte b) { | |
43 Colour c; | |
44 c.r = cast(float) r / 255f; | |
45 c.g = cast(float) g / 255f; | |
46 c.b = cast(float) b / 255f; | |
47 return c; | |
48 } | |
49 } | |
50 } |