Source

sphinx / Doc-26 / library / gl.rst

:mod:`gl` --- Graphics Library interface

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

Warning

Some illegal calls to the GL library cause the Python interpreter to dump core. 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 follows:

  • All (short, long, unsigned) int values are represented by Python integers.

  • All float and double values are represented by Python floating point numbers. 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, winopen('Hi There!') and 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 conventions:

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

import gl, GL, time

def main():
    gl.foreground()
    gl.prefposition(500, 900, 500, 900)
    w = gl.winopen('CrissCross')
    gl.ortho2(0.0, 400.0, 0.0, 400.0)
    gl.color(GL.WHITE)
    gl.clear()
    gl.color(GL.RED)
    gl.bgnline()
    gl.v2f(0.0, 0.0)
    gl.v2f(400.0, 400.0)
    gl.endline()
    gl.bgnline()
    gl.v2f(400.0, 0.0)
    gl.v2f(0.0, 400.0)
    gl.endline()
    time.sleep(5)

main()

:mod:`DEVICE` --- Constants used with the :mod:`gl` module

This modules defines the constants used by the Silicon Graphics Graphics Library that C programmers find in the header file <gl/device.h>. Read the module source file for details.

:mod:`GL` --- Constants used with the :mod:`gl` module

This module contains constants used by the Silicon Graphics Graphics Library from the C header file <gl/gl.h>. Read the module source file for details.