diff options
author | David Thompson <dthompson2@worcester.edu> | 2013-07-17 21:41:38 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2013-07-17 21:41:38 -0400 |
commit | e13fd4b0f6a3ada466585c7865ba7479c9e54ed3 (patch) | |
tree | ab7dd5b7dd8a74ee161109c54c23f3df93bacda1 /2d | |
parent | ecc09cfafd276e531f832b121e223ed105f174a0 (diff) |
Add rgba->gl-color procedure.
rgba->gl-color converts an RGBA color code in integer form into a list of color values for use with OpenGL calls.
For example, passing #xffffffff returns '(1.0 1.0 1.0 1.0).
Diffstat (limited to '2d')
-rw-r--r-- | 2d/helpers.scm | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/2d/helpers.scm b/2d/helpers.scm index 153b4b5..c919006 100644 --- a/2d/helpers.scm +++ b/2d/helpers.scm @@ -23,8 +23,10 @@ (define-module (2d helpers) #:use-module (srfi srfi-1) + #:use-module (rnrs arithmetic bitwise) #:export (any-equal? - logand?)) + logand? + rgba->gl-color)) (define (any-equal? elem . args) "Returns true if elem equals any of the arguments and returns false @@ -35,3 +37,15 @@ otherwise." "Returns true if the result of a bitwise AND of the integer arguments is non-zero and returns false otherwise." (not (zero? (apply logand args)))) + +(define (rgba->gl-color color) + "Converts an integer color code into OpenGL compatible color +values. Returns a list of four floating point numbers in range [0,1]." + (define (component offset) + (let ((mask (bitwise-arithmetic-shift-left #xff offset))) + (/ (bitwise-arithmetic-shift-right (logand mask color) offset) 255.0))) + + (list (component 24) + (component 16) + (component 8) + (component 0))) |