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/.
# 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
import_gl_to(my_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
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'
glutcbDisplayFunc (draw)
glutcbIdleFunc (idle)
glutcbKeyboardFunc(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, 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.
The initialization routines are mostly for internal use only. They include:
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.library
entry 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
.
|