cpython-withatomic / Doc / libgl.tex

\section{Built-in Module \sectcode{gl}}

This module provides access to the Silicon Graphics
{\em Graphics Library}.
It is available only on Silicon Graphics machines.

Some illegal calls to the GL library cause the Python interpreter to dump
In particular, the use of most GL calls is unsafe before the first
window is opened.

The module is too large to document here in its entirety, but the
following should help you to get started.
The parameter conventions for the C functions are translated to Python as

All (short, long, unsigned) int values are represented by Python
All float and double values are represented by Python floating point
In most cases, Python integers are also allowed.
All arrays are represented by one-dimensional Python lists.
In most cases, tuples are also allowed.
All string and character arguments are represented by Python strings,
for instance,
\code{winopen('Hi There!')}
\code{rotate(900, 'z')}.
All (short, long, unsigned) integer arguments or return values that are
only used to specify the length of an array argument are omitted.
For example, the C call

lmdef(deftype, index, np, props)
is translated to Python as

lmdef(deftype, index, props)
Output arguments are omitted from the argument list; they are
transmitted as function return values instead.
If more than one value must be returned, the return value is a tuple.
If the C function has both a regular return value (that is not omitted
because of the previous rule) and an output argument, the return value
comes first in the tuple.
Examples: the C call

getmcolor(i, &red, &green, &blue)
is translated to Python as

red, green, blue = getmcolor(i)

The following functions are non-standard or have special argument

\renewcommand{\indexsubitem}{(in module gl)}
%JHXXX the argument-argument added
Equivalent to but faster than a number of
The \var{argument} is a list (or tuple) of points.
Each point must be a tuple of coordinates
\code{(\var{x}, \var{y}, \var{z})} or \code{(\var{x}, \var{y})}.
The points may be 2- or 3-dimensional but must all have the
same dimension.
Float and int values may be mixed however.
The points are always converted to 3D double precision points
by assuming \code{\var{z} = 0.0} if necessary (as indicated in the man page),
and for each point
is called.

Equivalent to but faster than a number of
The argument is an array (list or tuple) of pairs of normals and points.
Each pair is a tuple of a point and a normal for that point.
Each point or normal must be a tuple of coordinates
\code{(\var{x}, \var{y}, \var{z})}.
Three coordinates must be given.
Float and int values may be mixed.
For each pair,
is called for the normal, and then
is called for the point.

Similar to 
but the pairs have the point first and the normal second.

\begin{funcdesc}{nurbssurface}{s_k\, t_k\, ctl\, s_ord\, t_ord\, type}
% XXX s_k[], t_k[], ctl[][]
Defines a nurbs surface.
The dimensions of
are computed as follows:
\code{[len(\var{s_k}) - \var{s_ord}]},
\code{[len(\var{t_k}) - \var{t_ord}]}.

\begin{funcdesc}{nurbscurve}{knots\, ctlpoints\, order\, type}
Defines a nurbs curve.
The length of ctlpoints is
\code{len(\var{knots}) - \var{order}}.

\begin{funcdesc}{pwlcurve}{points\, type}
Defines a piecewise-linear curve.
is a list of points.
must be

The only argument to these functions specifies the desired size of the
pick or select buffer.

These functions have no arguments.
They return a list of integers representing the used part of the
pick/select buffer.
No method is provided to detect buffer overrun.

Here is a tiny but complete example GL program in Python:

import gl, GL, time

def main():
    gl.prefposition(500, 900, 500, 900)
    w = gl.winopen('CrissCross')
    gl.ortho2(0.0, 400.0, 0.0, 400.0)
    gl.v2f(0.0, 0.0)
    gl.v2f(400.0, 400.0)
    gl.v2f(400.0, 0.0)
    gl.v2f(0.0, 400.0)

\section{Standard Modules \sectcode{GL} and \sectcode{DEVICE}}
\nodename{GL and DEVICE}

These modules define the constants used by the Silicon Graphics
{\em Graphics Library}
that C programmers find in the header files
Read the module source files for details.