OpenGL::GLFW - Perl bindings for the GLFW library
use OpenGL::GLFW qw(:all); use OpenGL::Modern qw(:all); # for OpenGL
OpenGL::GLFW provides perl5 bindings to the GLFW library for OpenGL applications development. The implementation is a direct translation of the GLFW C interface to perl. You can use the official GLFW documentation at http://www.glfw.org/documentation.html for the specifics of the GLFW API. The documentation here is on the perl usages and calling conventions.
At the top level, we have the following correspondences between these perl bindings and the C API:
GLFWwindow, GLFWmonitor, and GLFWcursor are opaque data types and pointers to them are returned as perl scalar references.
GLFWwindow
GLFWmonitor
GLFWcursor
GLFWvidmode, GLFWgammaramp, and GLFWimage types are mapped to perl hashes and passed and returned as the corresponding references.
GLFWvidmode
GLFWgammaramp
GLFWimage
The pointers to red, green, and blue channels of the gamma ramp become strings of packed ushort values.
Similarly, the pointer to pixels in the images use a packed string of 4 x width x height unsigned char values per pixel as [R,G,B,A] for pixels (0,0) through (width-1,height-1).
4 x width x height
[R,G,B,A]
(0,0)
(width-1,height-1)
See the examples/checkimg.pl for an example using the Perl Data Language module, PDL, to construct the the GLFWimage hash.
examples/checkimg.pl
The glfwSetXxxCallback routines do not implement the return value for the previous callback. If you need it, you'll need to track and save yourself.
Vulkan is not currently supported and glfwVulkanSupported always returns false.
glfwVulkanSupported
Neither glfwGetProcAddress nor glfwExtensionSupported are implemented. Please use the OpenGL::Modern or OpenGL modules instead.
glfwGetProcAddress
glfwExtensionSupported
None by default.
glfwSetWindowPosCallback($window, $cbfun) $windowpos_cbfun = sub ($window, $xpos, $ypos) { ... } glfwSetWindowSizeCallback($window, $cbfun) $windowsize_cbfun = sub ($window, $width, $height) { ... } glfwSetWindowCloseCallback($window, $cbfun) $windowclose_cbfun = sub ($window) { ... } glfwSetWindowRefreshCallback($window, $cbfun) $windowrefresh_cbfun = sub ($window) { ... } glfwSetWindowFocusCallback($window, $cbfun) $windowfocus_cbfun = sub ($window, $focused) { ... } glfwSetWindowIconifyCallback($window, $cbfun) $windowiconify_cbfun = sub ($window, $iconified) { ... } glfwSetFramebufferSizeCallback($window, $cbfun) $framebuffersize_cbfun = sub ($window, $width, $height) { ... } glfwSetKeyCallback($window, $cbfun) $key_cbfun = sub ($window, $key, $scancode, $action, $mods) { ... } glfwSetCharCallback($window, $cbfun) $char_cbfun = sub ($window, $codepoint) { ... } glfwSetCharModsCallback($window, $cbfun) $charmods_cbfun = sub ($window, $codepoint, $mods) { ... } glfwSetMouseButtonCallback($window, $cbfun) $mousebutton_cbfun = sub ($window, $button, $action, $mods) { ... } glfwSetCursorPosCallback($window, $cbfun) $cursorpos_cbfun = sub ($window, $xpos, $ypos) { ... } glfwSetCursorEnterCallback($window, $cbfun) $cursorenter_cbfun = sub ($window, $entered) { ... } glfwSetScrollCallback($window, $cbfun) $scroll_cbfun = sub ($window, $xoffset, $yoffset) { ... } glfwSetDropCallback($window, $cbfun) $drop_cbfun = sub ($window, $count, @paths) { ... }
glfwSetErrorCallback($cbfun) $error_cbfun = sub ($error, $description) { ... } glfwSetMonitorCallback($cbfun) $monitor_cbfun = sub ($monitor, $event) { ... } glfwSetJoystickCallback($cbfun) $joystick_cbfun = sub ($joy_id, $event) { ... }
glfwSetWindowIcon($window, $image_hash, ...) $cursor = glfwCreateCursor($image_hash, $xhot, $yhot) $cursor = glfwCreateStandardCursor($shape) glfwDestroyCursor($cursor) glfwSetCursor($window, $cursor)
where
$image_hash = { # The width, in pixels, of this image. width => $width, # The height, in pixels, of this image. height => $height, # The pixel data of this image, arranged # left-to-right, top-to-bottom in a packed # string of unsigned char data. pixels => $pixels }
$monitor = glfwGetPrimaryMonitor() @monitors = glfwGetMonitors() $name = glfwGetMonitorName($monitor) ($widthMM, $heightMM) = glfwGetMonitorPhysicalSize($monitor) ($xpos, $ypos) = glfwGetMonitorPos($monitor)
glfwSetGamma($monitor, $gamma) $gammaramp_hash = glfwGetGammaRamp($monitor) glfwSetGammaRamp($monitor, $gammaramp_hash)
$gammaramp_hash = { # An array of values describing the # response of the red channel as a # string of packed unsigned short data. red => $red, # An array of values describing the # response of the green channel as a # string of packed unsigned short data. green => $green, # An array of values describing the # response of the blue channel as a # string of packed unsigned short data. blue => $blue, # The number of elements in each array. size => $size }
$vidmode_hash = glfwGetVideoMode($monitor) @vidmodes = glfwGetVideoModes($monitor); # elements are vid mode hashes
$vidmode_hash = { # The width, in screen coordinates, of the video mode. width => $width, # The height, in screen coordinates, of the video mode. height => $height, # The bit depth of the red channel of the video mode. redBits => $redBits, # The bit depth of the green channel of the video mode. greenBits => $greenBits, # The bit depth of the blue channel of the video mode. blueBits => $blueBitsm, # The refresh rate, in Hz, of the video mode. refreshRate => $refreshRate }
$monitor = glfwGetWindowMonitor($window); # monitor of full screen window or undef? $window = glfwCreateWindow($width, $height, $title, $monitor or NULL, $share_window or NULL) glfwSetWindowMonitor($window, $monitor, $xpos, $ypos, $width, $height, $refreshRate) $window = glfwGetCurrentContext() $value = glfwGetInputMode($window, $mode) $pressed = glfwGetKey($window, $key) $pressed = glfwGetMouseButton($window, $button) $value = glfwGetWindowAttrib($window, $attrib) $value = glfwWindowShouldClose($window) glfwDestroyWindow($window) glfwFocusWindow($window) $string = glfwGetClipboardString($window) ($xpos, $ypos) = glfwGetCursorPos($window) ($width, $height) = glfwGetFramebufferSize($window) ($left, $top, $right, $bottom) = glfwGetWindowFrameSize($window) ($xpos, $ypos) = glfwGetWindowPos($window) ($width, $height) = glfwGetWindowSize($window) glfwHideWindow($window) glfwIconifyWindow($window) glfwMakeContextCurrent($window) glfwMaximizeWindow($window) glfwRestoreWindow($window) glfwSetClipboardString($window, $string) glfwSetCursorPos($window, $xpos, $ypos) glfwSetInputMode($window, $mode, $value) glfwSetWindowAspectRatio($window, $numer, $denom) glfwSetWindowPos($window, $xpos, $ypos) glfwSetWindowShouldClose($window, $value) glfwSetWindowSize($window, $width, $height) glfwSetWindowSizeLimits($window, $minwidth, $minheight, $maxwidth, $maxheight) glfwSetWindowTitle($window, $title) glfwSetWindowUserPointer($window, $ref) glfwShowWindow($window) glfwSwapBuffers($window) $ref = glfwGetWindowUserPointer($window) glfwDefaultWindowHints() ($major, $minor, $rev) = glfwGetVersion() glfwPollEvents() glfwPostEmptyEvent() glfwSetTime($time) glfwSwapInterval($interval) glfwTerminate() glfwWaitEvents() glfwWaitEventsTimeout($timeout) glfwWindowHint($hint, $value) $name = glfwGetJoystickName($joy) $name = glfwGetKeyName($key, $scancode) $version = glfwGetVersionString() @axes = glfwGetJoystickAxes($joy) @buttons = glfwGetJoystickButtons($joy) $status = glfwInit() $ispresent = glfwJoystickPresent($joy) $time = glfwGetTime() $frequency = glfwGetTimerFrequency() $timervalue = glfwGetTimerValue() $supported = glfwVulkanSupported()
glfwExtensionSupported glfwGetProcAddress
glfwGetRequiredInstanceExtensions glfwGetInstanceProcAddress glfwGetPhysicalDevicePresentationSupport glfwCreateWindowSurface
See the OpenGL::Modern module for the perl bindings for modern OpenGL APIs and the original perl OpenGL module bindings for OpenGL 1.x-2 with and some extensions.
Please use the Perl OpenGL mailing list at sf.net ask questions, provide feedback or to discuss OpenGL::GLFW.
Perl OpenGL IRC is at #pogl on irc.perl.org and may also be used for GLFW topics.
Chris Marshall, <chm@cpan.org>
Copyright (C) 2017 by Chris Marshall, <chm@cpan.org>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available.
To install OpenGL::GLFW, copy and paste the appropriate command in to your terminal.
cpanm
cpanm OpenGL::GLFW
CPAN shell
perl -MCPAN -e shell install OpenGL::GLFW
For more information on module installation, please visit the detailed CPAN module installation guide.