move around "general" in section title for neater formatting
[clinton/guile-figl.git] / doc / figl.texi
CommitLineData
8925f36f
AW
1\input texinfo @c -*-texinfo-*-
2@c %**start of header
3@setfilename figl.info
4@settitle Figl
5@c %**end of header
6
7@set VERSION 2.0.0
8@set UPDATED 1 February 2013
9
10@copying
11This manual is for Figl (version @value{VERSION}, updated
12@value{UPDATED})
13
14Copyright 2013 Andy Wingo and others.
15
16@quotation
17Figl is free software: you can redistribute and/or modify it and its
18documentation under the terms of the GNU Lesser General Public License
19as published by the Free Software Foundation, either version 3 of the
20License, or (at your option) any later version.
21
22Figl is distributed in the hope that it will be useful, but WITHOUT
23ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
25Public License for more details.
26
27You should have received a copy of the GNU Lesser General Public
28License along with this program. If not, see
29@uref{http://www.gnu.org/licenses/}.
30@end quotation
31
32Portions of this document were generated from the upstream OpenGL
33documentation. The work as a whole is redistributable under the
34license above. Sections containing generated documentation are
35prefixed with a specific copyright header.
36@end copying
37
38@dircategory The Algorithmic Language Scheme
39@direntry
40* Figl: (figl.info). An OpenGL interface for Guile.
41@end direntry
42
43@titlepage
44@title Figl
45@subtitle version @value{VERSION}, updated @value{UPDATED}
46@author Andy Wingo
47@author (many others)
48@page
49@vskip 0pt plus 1filll
50@insertcopying
51@end titlepage
52
53@ifnottex
54@node Top
55@top Figl
56
8925f36f 57@insertcopying
29d7cd47 58
8925f36f 59@menu
29d7cd47
AW
60* Introduction:: The what, why, and how of Figl.
61
1317e308 62* API Conventions:: General conventions used by the Figl APIs.
fb44a6aa 63
29d7cd47 64* GL:: A Scheme interface to OpenGL.
29d7cd47 65* GLU:: The GL Utility library.
29d7cd47 66* GLX:: Using OpenGL with the X Window System.
8f44ee57
AW
67* GLUT:: The GL Utility Toolkit.
68
69* FAQ:: Figl answers questions.
8925f36f
AW
70
71* Function Index::
72@end menu
73
74@end ifnottex
75
76@iftex
77@shortcontents
78@end iftex
79
29d7cd47
AW
80
81@node Introduction
82@chapter Introduction
83
84Figl is the Foreign Interface to GL: an OpenGL binding for Guile.
8f44ee57
AW
85
86OpenGL is a family of APIs and layers. The following chapters discuss
87the parts of OpenGL and how they are bound by Figl.
88
89But before that, some notes on the Figl binding as a whole.
90
91@menu
92* About Figl:: The structure of the binding.
93@end menu
94
95
96@node About Figl
97@section About Figl
98
99Figl is a @dfn{foreign} interface to OpenGL because it uses the
100dynamic @dfn{foreign function interface} provided by Guile 2.0,
101providing access to OpenGL without any C code at all. In fact, much
102of Figl (and this manual) is automatically generated from upstream API
29d7cd47
AW
103specifications and documentation.
104
8f44ee57
AW
105We have tried to do a very complete job at wrapping OpenGL, and
106additionally have tried to provide a nice Scheme interface as well.
107Our strategy has been to separate the binding into low-level and
108high-level pieces.
109
110The low-level bindings correspond exactly with the GL specification,
111and are well-documented. However, these interfaces are not so nice to
112use from Scheme; output arguments have to be allocated by the caller,
113and there is only the most basic level of type checking, and no sanity
114checking at all. For example, you can pass a bytevector of image data
115to the low-level @code{glTexImage2D} procedure, but no check is made
116that the dimensions you specify actually correspond to the size of the
117bytevector. This function could end up reading past the end of the
118bytevector. Worse things can happen with procedures that write to
119arrays, like @code{glGetTexImage}.
120
121The high-level bindings are currently a work in progress, and are
122being manually written. They intend to be a complete interface to the
123GL, without the need to use the low-level bindings. However, the
124low-level bindings will always be available for you to use if needed,
125and have the advantage that their behavior is better documented and
126specified by OpenGL itself.
127
128Low-level bindings are accessed by loading the @code{(figl
129@var{module} low-level)}, for example via:
130
131@example
132(use-modules (figl gl low-level))
133@end example
134
135The high-level modules are named like @code{(figl @var{module})}, for
136example @code{(figl gl)}.
137
138
1317e308
DH
139@node API Conventions
140@chapter API Conventions
fb44a6aa 141
aa1794f4 142FIXME: A very rough draft. Bindings and text are not fully synced
fb44a6aa
DH
143until more work is done here.
144
145This chapter documents the general API conventions used by Figl's
146various low-level and high-level bindings. Any conventions specific
aa1794f4 147to a particular module are documented in the relevent section.
fb44a6aa
DH
148
149As Figl is in very early stages of development these conventions are
150subject to change. Feedback is certainly welcome, and nothing is set
151in stone.
152
153@menu
154* Enumerations:: Using symbolic constants.
155* Functions:: Naming and behaviour.
156@c * State:: Accessing and mutating GL* state.
157@end menu
158
159
160@node Enumerations
161@section Enumerations
162
163The OpenGL API defines many @dfn{symbolic constants}, most of which
164are collected together as named @dfn{enumerations} or @dfn{bitfields}.
165Access to these constants in Figl is the same for the low-level
166bindings and high-level interface.
167
168For each OpenGL enumeration type, there is a similarly named Scheme
169type whose constructor takes an unquoted Scheme symbol naming one of
170the values. Figl translates the names to a more common Scheme style:
171
172@itemize @bullet
173@item any API prefix is removed (for example, GL_); and
174@item all names are lowercase, with underscores and CamelCase replaced by hyphens.
175@end itemize
176
177For example, the OpenGL API defines an enumeration with symbolic
178constants whose C names are GL_POINTS, GL_LINES, GL_TRIANGLES, and so
179on. Collectively they form the BeginMode enumeration type. To access
180these constants in Figl, apply the constant name to the enumeration
181type: @code{(begin-mode triangles)}.
182
183Bitfields are similar, though the constructor accepts multiple symbols
184and produces an appropriate mask.. In the GLUT API there is the
185DisplayMode bitfield, with symbolic constants GLUT_RGB, GLUT_INDEX,
186GLUT_SINGLE, and so on. To create a mask representing a
187double-buffered, rgb display-mode with a depth buffer:
188@code{(display-mode double rgb depth)}.
189
190Enumeration and bitfield values, once constructed, can be compared
191using @code{eqv?}. For example, to determine if @code{modelview} is
192the current matrix mode use
193@code{(eqv? (gl-matrix-mode) (matrix-mode modelview))}.
194
195
196@node Functions
197@section Functions
198
199The low-level bindings currently use names identical to their C API
200counterparts.
201
202High-level bindings adopt names that are closer to natural language,
203and a more common style for Scheme:
204
205@itemize @bullet
206@item the API prefix is always removed;
207@item abbreviations are avoided; and
208@item names are all lowercase with words separated by hyphens.
209@end itemize
210
211Some function names are altered in additional ways, to make clear
212which object is being operated on. Functions that mutate objects or
213state will have their name prefixed with @code{set-}, such as
214@code{set-matrix-mode}. FIXME: This choice may be too unnatural for GL
215users.
216
217Where the C API specifies multiple functions that perform a similar
218task on varying number and types of arguments, the high-level bindings
219provide a single function that takes optional arguments, and, where
220appropriate, using only the most natural type. Consider the group of
221C API functions including @code{glVertex2f}, @code{glVertex3f}, and so
222on; the high-level GL interface provides only a single function
223@code{glVertex}, with optional arguments.
224
225Packaged vector functions (such as @code{glColor3bv}) are combined in
226to a single high-level function with the suffice @code{-v}. Such a
227function will dispatch to the correct low-level binding based on the
228length and type of it's argument. There is no need to provide the
229length and type arguments specifically. For example,
230@code{(color #f32(1.0 0.0 0.8 0.5))} will determine that the argument
231is a float vector of length four, and dispatch to the low-level
232@code{glColor4fv}.
233
234The high-level interfaces often differ in other ways, and it is
235important to refer to the specific documentation.
236
237It is generally fine to intermix functions from corresponding
238low-level and high-level bindings. This can be useful if you know the
239specific type of data you are working with and want to avoid the
240overhead of dynamic dispatch at runtime. Any cases where such
241intermixing causes problems will be noted in the documentation for the
242high-level bindings.
243
244
22c0d71c 245@include gl.texi
8f44ee57 246
2668d475 247@include glu.texi
8925f36f 248
f17f286b 249@include glx.texi
29d7cd47 250
f17f286b 251@include glut.texi
8f44ee57
AW
252
253
254@node FAQ
255@chapter FAQ
256
257TODO: Write about things readers will want to know (instead of
258commenting them in the source :)
259
260
8925f36f
AW
261@node Function Index
262@unnumbered Function Index
263@printindex fn
264@bye