blob: abbaf1051cd33cccb780f4717984bf1b7ba2f4ae [file] [log] [blame]
Fred Drake3a0351c1998-04-04 07:23:21 +00001\section{Built-in Module \module{gl}}
Guido van Rossume47da0a1997-07-17 16:34:52 +00002\label{module-gl}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00003\bimodindex{gl}
4
5This module provides access to the Silicon Graphics
Fred Drakeaf8a0151998-01-14 14:51:31 +00006\emph{Graphics Library}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00007It is available only on Silicon Graphics machines.
8
9\strong{Warning:}
10Some illegal calls to the GL library cause the Python interpreter to dump
11core.
12In particular, the use of most GL calls is unsafe before the first
13window is opened.
14
15The module is too large to document here in its entirety, but the
16following should help you to get started.
17The parameter conventions for the C functions are translated to Python as
18follows:
19
20\begin{itemize}
21\item
22All (short, long, unsigned) int values are represented by Python
23integers.
24\item
25All float and double values are represented by Python floating point
26numbers.
27In most cases, Python integers are also allowed.
28\item
29All arrays are represented by one-dimensional Python lists.
30In most cases, tuples are also allowed.
31\item
32\begin{sloppypar}
33All string and character arguments are represented by Python strings,
34for instance,
35\code{winopen('Hi There!')}
36and
37\code{rotate(900, 'z')}.
38\end{sloppypar}
39\item
40All (short, long, unsigned) integer arguments or return values that are
41only used to specify the length of an array argument are omitted.
42For example, the C call
43
Fred Drake19479911998-02-13 06:58:54 +000044\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000045lmdef(deftype, index, np, props)
Fred Drake19479911998-02-13 06:58:54 +000046\end{verbatim}
Guido van Rossume47da0a1997-07-17 16:34:52 +000047%
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000048is translated to Python as
49
Fred Drake19479911998-02-13 06:58:54 +000050\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000051lmdef(deftype, index, props)
Fred Drake19479911998-02-13 06:58:54 +000052\end{verbatim}
Guido van Rossume47da0a1997-07-17 16:34:52 +000053%
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000054\item
55Output arguments are omitted from the argument list; they are
56transmitted as function return values instead.
57If more than one value must be returned, the return value is a tuple.
58If the C function has both a regular return value (that is not omitted
59because of the previous rule) and an output argument, the return value
60comes first in the tuple.
61Examples: the C call
62
Fred Drake19479911998-02-13 06:58:54 +000063\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000064getmcolor(i, &red, &green, &blue)
Fred Drake19479911998-02-13 06:58:54 +000065\end{verbatim}
Guido van Rossume47da0a1997-07-17 16:34:52 +000066%
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000067is translated to Python as
68
Fred Drake19479911998-02-13 06:58:54 +000069\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000070red, green, blue = getmcolor(i)
Fred Drake19479911998-02-13 06:58:54 +000071\end{verbatim}
Guido van Rossume47da0a1997-07-17 16:34:52 +000072%
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000073\end{itemize}
74
75The following functions are non-standard or have special argument
76conventions:
77
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000078\begin{funcdesc}{varray}{argument}
79%JHXXX the argument-argument added
80Equivalent to but faster than a number of
81\code{v3d()}
82calls.
83The \var{argument} is a list (or tuple) of points.
84Each point must be a tuple of coordinates
85\code{(\var{x}, \var{y}, \var{z})} or \code{(\var{x}, \var{y})}.
86The points may be 2- or 3-dimensional but must all have the
87same dimension.
88Float and int values may be mixed however.
89The points are always converted to 3D double precision points
90by assuming \code{\var{z} = 0.0} if necessary (as indicated in the man page),
91and for each point
92\code{v3d()}
93is called.
94\end{funcdesc}
95
96\begin{funcdesc}{nvarray}{}
97Equivalent to but faster than a number of
98\code{n3f}
99and
100\code{v3f}
101calls.
102The argument is an array (list or tuple) of pairs of normals and points.
103Each pair is a tuple of a point and a normal for that point.
104Each point or normal must be a tuple of coordinates
105\code{(\var{x}, \var{y}, \var{z})}.
106Three coordinates must be given.
107Float and int values may be mixed.
108For each pair,
109\code{n3f()}
110is called for the normal, and then
111\code{v3f()}
112is called for the point.
113\end{funcdesc}
114
115\begin{funcdesc}{vnarray}{}
116Similar to
117\code{nvarray()}
118but the pairs have the point first and the normal second.
119\end{funcdesc}
120
Fred Drakecce10901998-03-17 06:33:25 +0000121\begin{funcdesc}{nurbssurface}{s_k, t_k, ctl, s_ord, t_ord, type}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000122% XXX s_k[], t_k[], ctl[][]
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000123Defines a nurbs surface.
124The dimensions of
125\code{\var{ctl}[][]}
126are computed as follows:
127\code{[len(\var{s_k}) - \var{s_ord}]},
128\code{[len(\var{t_k}) - \var{t_ord}]}.
129\end{funcdesc}
130
Fred Drakecce10901998-03-17 06:33:25 +0000131\begin{funcdesc}{nurbscurve}{knots, ctlpoints, order, type}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000132Defines a nurbs curve.
133The length of ctlpoints is
134\code{len(\var{knots}) - \var{order}}.
135\end{funcdesc}
136
Fred Drakecce10901998-03-17 06:33:25 +0000137\begin{funcdesc}{pwlcurve}{points, type}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000138Defines a piecewise-linear curve.
139\var{points}
140is a list of points.
141\var{type}
142must be
143\code{N_ST}.
144\end{funcdesc}
145
146\begin{funcdesc}{pick}{n}
147\funcline{select}{n}
148The only argument to these functions specifies the desired size of the
149pick or select buffer.
150\end{funcdesc}
151
152\begin{funcdesc}{endpick}{}
153\funcline{endselect}{}
154These functions have no arguments.
155They return a list of integers representing the used part of the
156pick/select buffer.
157No method is provided to detect buffer overrun.
158\end{funcdesc}
159
160Here is a tiny but complete example GL program in Python:
161
Fred Drake19479911998-02-13 06:58:54 +0000162\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000163import gl, GL, time
164
165def main():
166 gl.foreground()
167 gl.prefposition(500, 900, 500, 900)
168 w = gl.winopen('CrissCross')
169 gl.ortho2(0.0, 400.0, 0.0, 400.0)
170 gl.color(GL.WHITE)
171 gl.clear()
172 gl.color(GL.RED)
173 gl.bgnline()
174 gl.v2f(0.0, 0.0)
175 gl.v2f(400.0, 400.0)
176 gl.endline()
177 gl.bgnline()
178 gl.v2f(400.0, 0.0)
179 gl.v2f(0.0, 400.0)
180 gl.endline()
181 time.sleep(5)
182
183main()
Fred Drake19479911998-02-13 06:58:54 +0000184\end{verbatim}
Guido van Rossume47da0a1997-07-17 16:34:52 +0000185%
Fred Drake3a0351c1998-04-04 07:23:21 +0000186\section{Standard Modules \module{GL} and \module{DEVICE}}
Guido van Rossum86cb0921995-03-20 12:59:56 +0000187\nodename{GL and DEVICE}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000188\stmodindex{GL}
189\stmodindex{DEVICE}
190
191These modules define the constants used by the Silicon Graphics
Fred Drakeaf8a0151998-01-14 14:51:31 +0000192\emph{Graphics Library}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000193that C programmers find in the header files
194\file{<gl/gl.h>}
195and
196\file{<gl/device.h>}.
197Read the module source files for details.