From 47d8a56dc01bbcd2cc0c5861f8060261001d9a1b Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Mon, 28 Jul 2008 14:19:35 -0500 Subject: [PATCH] opengl: Add words to work with color objects --- extra/opengl/opengl.factor | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/extra/opengl/opengl.factor b/extra/opengl/opengl.factor index be70b1e176..3964288666 100755 --- a/extra/opengl/opengl.factor +++ b/extra/opengl/opengl.factor @@ -2,10 +2,12 @@ ! Portions copyright (C) 2007 Eduardo Cavazos. ! Portions copyright (C) 2008 Joe Groff. ! See http://factorcode.org/license.txt for BSD license. + USING: alien alien.c-types continuations kernel libc math macros -namespaces math.vectors math.constants math.functions -math.parser opengl.gl opengl.glu combinators arrays sequences -splitting words byte-arrays assocs ; + namespaces math.vectors math.constants math.functions + math.parser opengl.gl opengl.glu combinators arrays sequences + splitting words byte-arrays assocs colors accessors ; + IN: opengl : coordinates ( point1 point2 -- x1 y2 x2 y2 ) @@ -14,6 +16,8 @@ IN: opengl : fix-coordinates ( point1 point2 -- x1 y2 x2 y2 ) [ first2 [ >fixnum ] bi@ ] bi@ ; + + : gl-color ( color -- ) first4 glColor4d ; inline : gl-clear-color ( color -- ) @@ -22,6 +26,16 @@ IN: opengl : gl-clear ( color -- ) gl-clear-color GL_COLOR_BUFFER_BIT glClear ; +: color>raw ( object -- 4array ) + >rgba + { [ red>> ] [ green>> ] [ blue>> ] [ alpha>> ] } cleave + 4array ; + +: set-color ( object -- ) color>raw first4 glColor4d ; +: set-clear-color ( object -- ) color>raw first4 glClearColor ; + + + : gl-error ( -- ) glGetError dup zero? [ "GL error: " over gluErrorString append throw