blob: d9d0de163a2ecc4e4279f8e3e3c5b7d9df595e21 [file] [log] [blame]
Georg Brandl8ec7f652007-08-15 14:28:01 +00001
2:mod:`gl` --- *Graphics Library* interface
3==========================================
4
5.. module:: gl
6 :platform: IRIX
7 :synopsis: Functions from the Silicon Graphics Graphics Library.
8
9
10This module provides access to the Silicon Graphics *Graphics Library*. It is
11available only on Silicon Graphics machines.
12
13.. warning::
14
15 Some illegal calls to the GL library cause the Python interpreter to dump core.
16 In particular, the use of most GL calls is unsafe before the first window is
17 opened.
18
19The module is too large to document here in its entirety, but the following
20should help you to get started. The parameter conventions for the C functions
21are translated to Python as follows:
22
23* All (short, long, unsigned) int values are represented by Python integers.
24
25* All float and double values are represented by Python floating point numbers.
26 In most cases, Python integers are also allowed.
27
28* All arrays are represented by one-dimensional Python lists. In most cases,
29 tuples are also allowed.
30
31* All string and character arguments are represented by Python strings, for
32 instance, ``winopen('Hi There!')`` and ``rotate(900, 'z')``.
33
34* All (short, long, unsigned) integer arguments or return values that are only
35 used to specify the length of an array argument are omitted. For example, the C
36 call ::
37
38 lmdef(deftype, index, np, props)
39
40 is translated to Python as ::
41
42 lmdef(deftype, index, props)
43
44* Output arguments are omitted from the argument list; they are transmitted as
45 function return values instead. If more than one value must be returned, the
46 return value is a tuple. If the C function has both a regular return value (that
47 is not omitted because of the previous rule) and an output argument, the return
48 value comes first in the tuple. Examples: the C call ::
49
50 getmcolor(i, &red, &green, &blue)
51
52 is translated to Python as ::
53
54 red, green, blue = getmcolor(i)
55
56The following functions are non-standard or have special argument conventions:
57
58
59.. function:: varray(argument)
60
61 Equivalent to but faster than a number of ``v3d()`` calls. The *argument* is a
62 list (or tuple) of points. Each point must be a tuple of coordinates ``(x, y,
63 z)`` or ``(x, y)``. The points may be 2- or 3-dimensional but must all have the
64 same dimension. Float and int values may be mixed however. The points are always
65 converted to 3D double precision points by assuming ``z = 0.0`` if necessary (as
66 indicated in the man page), and for each point ``v3d()`` is called.
67
68 .. % JHXXX the argument-argument added
69
70
71.. function:: nvarray()
72
73 Equivalent to but faster than a number of ``n3f`` and ``v3f`` calls. The
74 argument is an array (list or tuple) of pairs of normals and points. Each pair
75 is a tuple of a point and a normal for that point. Each point or normal must be
76 a tuple of coordinates ``(x, y, z)``. Three coordinates must be given. Float and
77 int values may be mixed. For each pair, ``n3f()`` is called for the normal, and
78 then ``v3f()`` is called for the point.
79
80
81.. function:: vnarray()
82
83 Similar to ``nvarray()`` but the pairs have the point first and the normal
84 second.
85
86
87.. function:: nurbssurface(s_k, t_k, ctl, s_ord, t_ord, type)
88
89 Defines a nurbs surface. The dimensions of ``ctl[][]`` are computed as follows:
90 ``[len(s_k) - s_ord]``, ``[len(t_k) - t_ord]``.
91
92 .. % XXX s_k[], t_k[], ctl[][]
93
94
95.. function:: nurbscurve(knots, ctlpoints, order, type)
96
97 Defines a nurbs curve. The length of ctlpoints is ``len(knots) - order``.
98
99
100.. function:: pwlcurve(points, type)
101
102 Defines a piecewise-linear curve. *points* is a list of points. *type* must be
103 ``N_ST``.
104
105
106.. function:: pick(n)
107 select(n)
108
109 The only argument to these functions specifies the desired size of the pick or
110 select buffer.
111
112
113.. function:: endpick()
114 endselect()
115
116 These functions have no arguments. They return a list of integers representing
117 the used part of the pick/select buffer. No method is provided to detect buffer
118 overrun.
119
120Here is a tiny but complete example GL program in Python::
121
122 import gl, GL, time
123
124 def main():
125 gl.foreground()
126 gl.prefposition(500, 900, 500, 900)
127 w = gl.winopen('CrissCross')
128 gl.ortho2(0.0, 400.0, 0.0, 400.0)
129 gl.color(GL.WHITE)
130 gl.clear()
131 gl.color(GL.RED)
132 gl.bgnline()
133 gl.v2f(0.0, 0.0)
134 gl.v2f(400.0, 400.0)
135 gl.endline()
136 gl.bgnline()
137 gl.v2f(400.0, 0.0)
138 gl.v2f(0.0, 400.0)
139 gl.endline()
140 time.sleep(5)
141
142 main()
143
144
145.. seealso::
146
147 `PyOpenGL: The Python OpenGL Binding <http://pyopengl.sourceforge.net/>`_
148 .. index::
149 single: OpenGL
150 single: PyOpenGL
151
152 An interface to OpenGL is also available; see information about the **PyOpenGL**
153 project online at http://pyopengl.sourceforge.net/. This may be a better option
154 if support for SGI hardware from before about 1996 is not required.
155
156
157:mod:`DEVICE` --- Constants used with the :mod:`gl` module
158==========================================================
159
160.. module:: DEVICE
161 :platform: IRIX
162 :synopsis: Constants used with the gl module.
163
164
165This modules defines the constants used by the Silicon Graphics *Graphics
166Library* that C programmers find in the header file ``<gl/device.h>``. Read the
167module source file for details.
168
169
170:mod:`GL` --- Constants used with the :mod:`gl` module
171======================================================
172
173.. module:: GL
174 :platform: IRIX
175 :synopsis: Constants used with the gl module.
176
177
178This module contains constants used by the Silicon Graphics *Graphics Library*
179from the C header file ``<gl/gl.h>``. Read the module source file for details.
180