NAME

OpenGL::GLFW - Perl bindings for the GLFW library

SYNOPSIS

use OpenGL::GLFW qw(:all);
use OpenGL::Modern qw(:all);  # for OpenGL

DESCRIPTION

OpenGL::GLFW provides perl5 bindings to the GLFW library for OpenGL, OpenGL ES, and Vulkan application development. This is a simple translation of the GLFW C interface to perl so you can use that documentation at http://www.glfw.org/documentation.html for the specifics of the API.

This will be cleaned up for the first official release of OpenGL::GLFW but for these first bindings we have the following correspondences between the perl bindings and the C API:

  • GLFWwindow, GLFWmonitor, and GLFWcursor are opaque data types and pointers to them are returned as perl scalar references.

  • GLFWvidmode, GLFWgammaramp, and GLFWimage types are mapped to perl hashes and passed and returned as the corresponding references.

    The pointers to red, green, and blue channels of the gamma ramp become to strings of packed ushort values.

    Similarly, the pointer to pixels in the images use a packed string of the 4 x width x height unsigned character values by pixel as R,G,B,A for pixel (0,0) through pixel (w-1,h-1).

    See the examples/checkimg.pl for an example using the Perl Data Language module, PDL, to construct the the GLFWimage hash.

  • 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 alwyas returns false.

  • Neither glfwGetProcAddress nor glfwExtensionSupported are implemented. Plesae use the OpenGL::Modern or OpenGL bindings instead.

EXPORT

None by default.

PERL USAGE

Per-window callbacks

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) { ... }

Global callbacks

glfwSetErrorCallback($cbfun)
$error_cbfun = sub ($error, $description) { ... }

glfwSetMonitorCallback($cbfun)
$monitor_cbfun = sub ($monitor, $event) { ... }

glfwSetJoystickCallback($cbfun)
$joystick_cbfun = sub ($joy_id, $event) { ... }

Icons/Cursors/Images

glfwSetWindowIcon($window, { image hash }, ...)

$cursor = glfwCreateCursor({ image hash }, xhot, yhot)

$cursor = glfwCreateStandardCursor($shape)

glfwDestroyCursor($cursor)

glfwSetCursor($window, $cursor)

Monitors/Windows and the rest

$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)

$vidmode_hash = glfwGetVideoMode($monitor)

@vidmodes = glfwGetVideoModes($monitor);  # elements are vid mode hashes

$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()

OpenGL not supported (use GLEW)

glfwExtensionSupported

glfwGetProcAddress

Vulkan not supported

glfwGetRequiredInstanceExtensions

glfwGetInstanceProcAddress

glfwGetPhysicalDevicePresentationSupport

glfwCreateWindowSurface

SEE ALSO

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.

AUTHOR

Chris Marshall, <chm@cpan.org>

COPYRIGHT AND LICENSE

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.