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