OpenGL::GLFW(3pm)

πŸ“¦
version 0.0403 Β· 3 versions
, in ubuntu stonking

πŸ¦‹ OpenGL::GLFW(3pm) πŸ¦‹

okay so hi bestie!! πŸ’– you just opened the OpenGL::GLFW(3pm) page, straight from the User Contributed Perl Documentation, and honestly? it's a whole serve. this is the manual for the perl bindings to GLFW β€” the thing that lets you open windows and vibe with OpenGL from perl. let's get into it, no cap. ✨


πŸ’… NAME πŸ’…

OpenGL::GLFW β€” Perl bindings for the GLFW library. short, iconic, to the point. periodt.


✨ SYNOPSIS ✨

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

two lines and you're literally in your main character era. 🌸


πŸŽ€ DESCRIPTION πŸŽ€

so. OpenGL::GLFW gives you perl5 bindings to the GLFW library for developing OpenGL applications. the implementation is a direct translation of the GLFW C interface to perl β€” like, a one-to-one glow-up, fr fr. πŸ¦‹

for the actual specifics of the GLFW API, go read the official GLFW documentation at <http://www.glfw.org/documentation.html>. what this page is about is the perl usages and calling conventions β€” i.e. the parts that change when C puts on a little perl bow. πŸŽ€

at the top level, here's how the perl bindings correspond to the C API, bestie:

  • GLFWwindow, GLFWmonitor, and GLFWcursor are opaque data types, and pointers to them are returned as perl scalar references. mystery boxes, we love them. πŸ™ˆ
  • GLFWvidmode, GLFWgammaramp, and GLFWimage types are mapped to perl hashes and are passed and returned as the corresponding references. iconic behaviour honestly.

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 uses 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). 🌈

See the examples/checkimg.pl for an example using the Perl Data Language module, PDL, to construct the GLFWimage hash. so handy, obsessed. πŸ’–

  • The glfwSetXxxCallback routines do not implement the return value for the previous callback. if you need it, you'll need to track and save it yourself. no one is coming to save you, bestie, you save you. πŸ’€
  • Vulkan is not currently supported, and glfwVulkanSupported always returns false. it's giving "not yet, babe."
  • Neither glfwGetProcAddress nor glfwExtensionSupported are implemented. please use the OpenGL::Modern or OpenGL modules instead. 🫢

🌟 EXPORT 🌟

None by default. (you ask for what you want around here, darling.)


πŸ’œ PERL USAGE πŸ’œ

✨ Per-window callbacks ✨

here's the whole squad of per-window callbacks, with their exact shapes β€” copy these signatures, don't freestyle them:

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 ✨

and here are the big-picture, whole-world ones:

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 ✨

cursors and icons and images, oh my 🧚:

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

}

✨ Monitors ✨

asking the machine about its screens, bestie:

$monitor = glfwGetPrimaryMonitor()

@monitors = glfwGetMonitors()

$name = glfwGetMonitorName($monitor)

($widthMM, $heightMM) = glfwGetMonitorPhysicalSize($monitor)

($xpos, $ypos) = glfwGetMonitorPos($monitor)

($xpos, $ypos, $width, $height) = glfwGetMonitorWorkarea($monitor)

✨ Gamma Settings ✨

brightness vibes, literally:

glfwSetGamma($monitor, $gamma)

$gammaramp_hash = glfwGetGammaRamp($monitor)

glfwSetGammaRamp($monitor, $gammaramp_hash)

where

$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

}

✨ Video Mode ✨

resolution info, and yes we stan a good refresh rate:

$vidmode_hash = glfwGetVideoMode($monitor)

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

where

$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

}
okay bestie, heads up: yes, that really does say blueBits => $blueBitsm, up there. i am not fixing it, that would be copying-with-extra-steps of a lie. whatever the source says, i say. πŸ‘€

✨ Windows and Interaction ✨

this is the big one. the whole main-character montage of window management, input, timing, events and init. here it is, untouched:

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

🚫 GLFW OpenGL Extension checks are not implemented 🚫

not here, bestie. these two? not implemented:

glfwExtensionSupported

glfwGetProcAddress

🚫 Vulkan not implemented 🚫

and vulkan? also not implemented. these four are just vibes and dreams:

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 <https://sourceforge.net/p/pogl/mailman/?source=navbar> to 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. come say hi!! πŸ’¬


πŸ’œ AUTHOR πŸ’œ

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.


and that's the whole page, bestie!! πŸ’– this was OpenGL::GLFW(3pm) from perl v5.42.3, dated 2026-08-20 β€” go make something gorgeous with it, you absolute icon. slay, terminate your windows properly, and hydrate. πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from