|parrotcode: Parrot extension for OpenGL bindings|
|Contents | Libraries|
OpenGL - Parrot extension for OpenGL bindings
This covers only the basic OpenGL and GLUT initialization. For more, look in examples/opengl/, starting with examples/opengl/triangle.pir.
# 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 import_gl = get_global ['OpenGL'], '_export_all_functions' import_gl() # 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 glutInitDisplayMode(mode) .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' glutDisplayFunc (draw) glutIdleFunc (idle) glutKeyboardFunc(keyboard) # Enter the GLUT main loop glutMainLoop() .end
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 -- for heavy drawing code, it is sometimes difficult to tell the difference except for the leading period on PIR constant names and lack of trailing semicolons on each line.
The following sections describe features of Parrot's OpenGL bindings that are not part of the core C binding, or where they differ non-trivially.
The initialization routines are mostly for internal use only. They include:
fallback_listshould be a simple array of strings, each naming one of the possible filenames, without the trailing shared library extension (e.g.
friendly_nameis only used to fill in the error message in case no match can be found on the system.
libraryentry point in
nci_list, and store the results in
namespace. The list should consist of alternating function names and Parrot NCI signatures.
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.
namespace. Unmangles callback names, so that the receiving namespace sees the standard names instead of the mangled versions. If
to_namespaceis missing, then the caller's namespace is assumed.