OpenGL - Parrot extension for OpenGL bindings


This covers only the basic OpenGL and GLUT initialization. For more, look in examples/opengl/.

 # Include OpenGL constants
 .include 'opengl_defines.pasm'

 .sub main :main
    .param pmc argv

    # Load OpenGL libary and a helper library for calling glutInit
    load_bytecode 'library/OpenGL.pbc'
    load_bytecode 'library/NCI/call_toolkit_init.pbc'

    # Import all OpenGL/GLU/GLUT functions
    .local pmc import_gl_to, my_namespace
    import_gl_to = get_global ['OpenGL'], '_export_all_functions_to'
    my_namespace = get_namespace


    # Initialize GLUT
    .local pmc call_toolkit_init
    call_toolkit_init = get_global ['NCI'], 'call_toolkit_init'

    .const .Sub glutInit = 'glutInit'
    argv = call_toolkit_init(glutInit, argv)

    # Set display mode, create GLUT window, save window handle
    .local int mode
    mode = .GLUT_DOUBLE | .GLUT_RGBA

    .local pmc window
    window = new 'Integer'
    window = glutCreateWindow('My Window Title')
    set_global 'glut_window', window

    # Set up GLUT callbacks
    .const .Sub draw     = 'draw'
    .const .Sub idle     = 'idle'
    .const .Sub keyboard = 'keyboard'
    glutcbDisplayFunc (draw)
    glutcbIdleFunc    (idle)

    # Enter the GLUT main loop


This library is a straightforward Parrot NCI wrapper for OpenGL, GLU, and GLUT. It is still a work in progress; work will generally start with the oldest, most widely supported functions and progress to the most recently standardized calls. Generally you will find programming GLUT in PIR to be similar to GLUT in C, with the exception of the renaming of glut*Func to glutcb*Func to work around some current Parrot limitations.

The following sections describe other differences from OpenGL in C.

Initialization ^

The initialization routines are mostly for internal use only. They include:


At module load time, calls the other initialization routines in the proper order.


Opens all relevent OpenGL system libraries. For portability, tries each of the known different filenames for each library in turn before giving up.

_load_lib_with_fallbacks(string friendly_name, pmc fallback_list)

This function is more generally useful than just for this module -- it implements the search for a particular libary that may appear under any of several different filenames. The fallback_list should be a simple array of strings, each naming one of the possible filenames, without the trailing shared library extension (e.g. .dll or .so). The friendly_name is only used to fill in the error message in case no match can be found on the system.


Create NCI wrappers for all GL, GLU, and GLUT functions

_wrap_nci_list(pmc namespace, pmc library, pmc nci_list)

Create NCI wrappers for every library entry point in nci_list, and store the results in namespace . The list should consist of alternating function names and Parrot NCI signatures.

Symbol Export ^

These routines allow OpenGL symbols to exported to other namespaces to more directly replicate the normal OpenGL coding style. Most calling programs will want to use at least one of these, probably immediately after loading this library.

_export_all_functions_to(pmc namespace)

Export all OpenGL/GLU/GLUT functions to the target namespace.