2 ;;; Copyright (C) 2013 Andy Wingo <wingo@pobox.com>
3 ;;; Copyright (C) 2013 Daniel Hartwig <mandyke@gmail.com>
5 ;;; Figl is free software: you can redistribute it and/or modify it
6 ;;; under the terms of the GNU Lesser General Public License as
7 ;;; published by the Free Software Foundation, either version 3 of the
8 ;;; License, or (at your option) any later version.
10 ;;; Figl is distributed in the hope that it will be useful, but WITHOUT
11 ;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 ;;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
13 ;;; Public License for more details.
15 ;;; You should have received a copy of the GNU Lesser General Public
16 ;;; License along with this program. If not, see
17 ;;; <http://www.gnu.org/licenses/>.
25 (define-module (figl gl)
26 #:use-module (figl runtime)
27 #:use-module (figl gl enums)
28 #:use-module ((figl gl low-level) #:renamer (symbol-prefix-proc '%)))
30 ;; Notice there is no #:export clause. Exports are done inline to
31 ;; facilitate re-exporting low-level bindings (and changing that
32 ;; choice), and identifying gaps in the API.
34 ;; There are two sets of exports for each section. The first is for
35 ;; bindings defined in the specification, exported in order. The
36 ;; second is for additional procedures not defined by the spec. but
37 ;; relevant to the section, for example with-gl-begin.
39 ;; At least keep this format until the bindings are fairly complete.
41 (module-use! (module-public-interface (current-module))
42 (resolve-interface '(figl gl enums)))
45 ;;; 2.6 Begin/End Paradigm
48 ;; emacs: (put! 'gl-begin 'scheme-indent-function 1)
49 (define-syntax gl-begin
51 ((_ mode body1 body2 ...)
58 (apply values vals))))))
60 (define (gl-edge-flag flag)
61 (%glEdgeFlag (if flag (boolean true) (boolean false))))
63 (export-syntax gl-begin)
68 ;;; 2.7 Vertex Specification
71 ;; Note that these are float variants only. This has implications for
72 ;; some functions whose integer variants normalize their arguments.
73 ;; The corresponding float variants expect normalized input, usually
74 ;; in the range [0, 1]. Refer to the OpenGL specification for
77 ;; For access to non-float variants please use the appropriate
80 ;; TODO: Maybe re-export packaged variants here. Unpacked byte
83 (define* (gl-vertex x y #:optional (z 0.0) (w 1.0))
84 (%glVertex4f x y z w))
86 (define* (gl-tex-coord s #:optional (t 0.0) (r 0.0) (q 1.0))
87 (%glTexCoord4f s t r q))
89 (define* (gl-multi-tex-coord texture s #:optional (t 0.0) (r 0.0) (q 1.0))
90 (%glMultiTexCoord4f texture s t r q))
92 (define* (gl-color red green blue #:optional (alpha 1.0))
93 (%glColor4f red green blue alpha))
95 (define* (gl-vertex-attrib index x #:optional (y 0.0) (z 0.0) (w 1.0))
96 (%glVertexAttrib4f index x y z w))
103 (re-export (%glNormal3f . gl-normal)
104 (%glFogCoordf . gl-fog-coord)
105 (%glSecondaryColor3f . gl-secondary-color)
106 (%glIndexi . gl-index))
112 (re-export (%glRectf . gl-rectangle))
116 ;;; 2.11 Coordinate Transformation
120 ;;; 2.11.1 Controlling the Viewport
123 (re-export (%glDepthRange . gl-depth-range)
124 (%glViewport . gl-viewport))
130 ;; OpengGL matrices are stored in column-major order. This is
131 ;; different to the usual row-major order used in 2-dimensional
132 ;; arrays, which will have to be transposed as they loaded.
134 (define* (gl-load-matrix m #:key (transpose #f))
136 %glLoadTransposeMatrixf
140 (define* (gl-multiply-matrix m #:key (transpose #f))
142 %glMultTransposeMatrixf
146 (export gl-load-matrix
149 (re-export (%glMatrixMode . gl-matrix-mode)
150 (%glLoadIdentity . gl-load-identity)
151 (%glRotatef . gl-rotate)
152 (%glTranslatef . gl-translate)
153 (%glScalef . gl-scale)
154 (%glFrustum . gl-frustum)
155 (%glOrtho . gl-ortho)
156 (%glActiveTexture . set-gl-active-texture)
157 (%glPushMatrix . gl-push-matrix)
158 (%glPopMatrix . gl-pop-matrix))
160 (define-syntax with-gl-push-matrix
168 (export-syntax with-gl-push-matrix)
171 ;;; 2.11.3 Normal Transformations
174 (re-export (%glEnable . gl-enable)
175 (%glDisable . gl-disable))