use pairs in renaming re-exports
[clinton/guile-figl.git] / figl / gl.scm
CommitLineData
be421aed
AW
1;;; figl
2;;; Copyright (C) 2013 Andy Wingo <wingo@pobox.com>
1547f980 3;;; Copyright (C) 2013 Daniel Hartwig <mandyke@gmail.com>
be421aed
AW
4;;;
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.
9;;;
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.
14;;;
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/>.
18
19;;; Commentary:
20;;
21;; OpenGL binding.
22;;
23;;; Code:
24
25(define-module (figl gl)
26 #:use-module (figl runtime)
1547f980
DH
27 #:use-module (figl gl enums)
28 #:use-module ((figl gl low-level) #:renamer (symbol-prefix-proc '%)))
be421aed 29
1547f980
DH
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.
33;;
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.
38;;
39;; At least keep this format until the bindings are fairly complete.
40
41(module-use! (module-public-interface (current-module))
42 (resolve-interface '(figl gl enums)))
43
44;;;
45;;; 2.6 Begin/End Paradigm
46;;;
47
48(define (gl-edge-flag flag)
49 (%glEdgeFlag (if flag (boolean true) (boolean false))))
50
8c6d5fbb
DH
51(re-export (%glBegin . gl-begin)
52 (%glEnd . gl-end))
1547f980
DH
53
54(export gl-edge-flag)
55
56(define-syntax with-gl-begin ; terrible name
57 (syntax-rules ()
58 ((_ mode body ...)
59 (begin
8c6d5fbb 60 (gl-begin mode)
1547f980 61 body ...
8c6d5fbb 62 (gl-end)))))
1547f980
DH
63
64(export-syntax with-gl-begin)
65
66;;;
67;;; 2.7 Vertex Specification
68;;;
69
70;; Note that these are float variants only. This has implications for
71;; some functions whose integer variants normalize their arguments.
72;; The corresponding float variants expect normalized input, usually
73;; in the range [0, 1]. Refer to the OpenGL specification for
74;; details.
75;;
76;; For access to non-float variants please use the appropriate
77;; low-level binding.
78
79;; TODO: Maybe re-export packaged variants here. Unpacked byte
80;; variants?
81
82(define* (gl-vertex x y #:optional (z 0.0) (w 1.0))
83 (%glVertex4f x y z w))
84
85(define* (gl-tex-coord s #:optional (t 0.0) (r 0.0) (q 1.0))
86 (%glTexCoord4f s t r q))
87
88(define* (gl-multi-tex-coord texture s #:optional (t 0.0) (r 0.0) (q 1.0))
89 (%glMultiTexCoord4f texture s t r q))
90
91(define* (gl-color red green blue #:optional (alpha 1.0))
92 (%glColor4f red green blue alpha))
93
94(define* (gl-vertex-attrib index x #:optional (y 0.0) (z 0.0) (w 1.0))
95 (%glVertexAttrib4f index x y z w))
96
97(export gl-vertex
98 gl-tex-coord
99 gl-multi-tex-coord
100 gl-color)
101
8c6d5fbb
DH
102(re-export (%glNormal3f . gl-normal)
103 (%glFogCoordf . gl-fog-coord)
104 (%glSecondaryColor3f . gl-secondary-color)
105 (%glIndexi . gl-index))
1547f980
DH
106
107;;;
108;;; 2.10 Rectangles
109;;;
110
8c6d5fbb 111(re-export (%glRectf . gl-rectangle))
96e10a21
DH
112
113\f
114;;;
115;;; 2.11 Coordinate Transformation
116;;;
117
118;;;
119;;; 2.11.1 Controlling the Viewport
120;;;
121
8c6d5fbb
DH
122(re-export (%glDepthRange . gl-depth-range)
123 (%glViewport . gl-viewport))
96e10a21
DH
124
125;;;
126;;; 2.11.2 Matrices
127;;;
128
129;; OpengGL matrices are stored in column-major order. This is
130;; different to the usual row-major order used in 2-dimensional
131;; arrays, which will have to be transposed as they loaded.
132
133(define* (gl-load-matrix m #:key (transpose #f))
134 ((if transpose
135 %glLoadTransposeMatrixf
136 %glLoadMatrixf)
137 (array-contents m)))
138
139(define* (gl-multiply-matrix m #:key (transpose #f))
140 ((if transpose
141 %glMultTransposeMatrixf
142 %glMultMatrixf)
143 (array-contents m)))
144
145(export gl-load-matrix
146 gl-multiply-matrix)
147
8c6d5fbb
DH
148(re-export (%glMatrixMode . gl-matrix-mode)
149 (%glLoadIdentity . gl-load-identity)
150 (%glRotatef . gl-rotate)
151 (%glTranslatef . gl-translate)
152 (%glScalef . gl-scale)
153 (%glFrustum . gl-frustum)
154 (%glOrtho . gl-ortho)
155 (%glActiveTexture . set-gl-active-texture)
156 (%glPushMatrix . gl-push-matrix)
157 (%glPopMatrix . gl-pop-matrix))
96e10a21
DH
158
159(define-syntax with-gl-push-matrix
160 (syntax-rules ()
161 ((_ body ...)
162 (begin
163 (%glPushMatrix)
164 body ...
165 (%glPopMatrix)))))
166
167(export-syntax with-gl-push-matrix)
168
169;;;
170;;; 2.11.3 Normal Transformations
171;;;
172
8c6d5fbb
DH
173(re-export (%glEnable . gl-enable)
174 (%glDisable . gl-disable))