Struct glfw::Glfw [−][src]
#[non_exhaustive]pub struct Glfw;
Expand description
A token from which to call various GLFW functions. It can be obtained by
calling the init
function. This cannot be sent to other tasks, and should
only be initialized on the main platform thread. Whilst this might make
performing some operations harder, this is to ensure thread safety is enforced
statically.
Implementations
pub fn set_error_callback<UserData: 'static>(
&mut self,
callback: Option<ErrorCallback<UserData>>
)
pub fn set_error_callback<UserData: 'static>(
&mut self,
callback: Option<ErrorCallback<UserData>>
)
Sets the error callback, overwriting the previous one stored.
Example
use std::cell::Cell; fn error_callback(_: glfw::Error, description: String, error_count: &Cell<usize>) { println!("GLFW error {}: {}", error_count.get(), description); error_count.set(error_count.get() + 1); } // sets a new callback glfw.set_error_callback(Some( glfw::Callback { f: error_callback, data: Cell::new(0), } )); // removes the previously set callback glfw.set_error_callback(None);
The FAIL_ON_ERRORS
and LOG_ERRORS
callbacks are provided for
convenience. For example:
// triggers a task failure when a GLFW error is encountered. glfw.set_error_callback(glfw::FAIL_ON_ERRORS);
pub fn set_monitor_callback<UserData: 'static>(
&mut self,
callback: Option<MonitorCallback<UserData>>
)
pub fn set_monitor_callback<UserData: 'static>(
&mut self,
callback: Option<MonitorCallback<UserData>>
)
Sets the monitor callback, overwriting the previous one stored.
pub fn set_joystick_callback<UserData: 'static>(
&mut self,
callback: Option<JoystickCallback<UserData>>
)
pub fn set_joystick_callback<UserData: 'static>(
&mut self,
callback: Option<JoystickCallback<UserData>>
)
Sets the joystick callback, overwriting the previous one stored
Supplies the primary monitor to the closure provided, if it exists. This is usually the monitor where elements like the Windows task bar or the OS X menu bar is located.
Example
let (window, events) = glfw.with_primary_monitor(|_, m| { glfw.create_window(300, 300, "Hello this is window", m.map_or(glfw::WindowMode::Windowed, |m| glfw::FullScreen(m))) }).expect("Failed to create GLFW window.");
Supplies the primary monitor to the closure provided, if it exists. This is usually the monitor where elements like the Windows task bar or the OS X menu bar is located.
Variant that can accept an FnMut
closure.
Example
glfw.with_primary_monitor(|_: &mut _, m: Option<&glfw::Monitor>| { let monitor = m.unwrap(); let mode: glfw::VidMode = monitor.get_video_mode().unwrap(); // Modifying `window` requires `FnMut` window.set_monitor(glfw::WindowMode::FullScreen(&monitor), 0, 0, mode.width, mode.height, Some(mode.refresh_rate)); });
Supplies a vector of the currently connected monitors to the closure provided.
Example
glfw.with_connected_monitors(|_, monitors| { for monitor in monitors.iter() { println!("{}: {}", monitor.get_name(), monitor.get_video_mode()); } });
Supplies a vector of the currently connected monitors to the closure provided.
Variant that can accept an FnMut
closure.
Example
glfw.with_connected_monitors(|_, monitors| { for monitor in monitors.iter() { println!("{}: {}", monitor.get_name(), monitor.get_video_mode()); } });
Queries Vulkan support via glfwVulkanSupported
This is used to set the window hints for the next call to
Glfw::create_window
. The hints can be reset to their default values
using calling the Glfw::default_window_hints
function.
Wrapper for glfwWindowHint
OpenGL 3.x and 4.x on Mac OS X
The only OpenGL 3.x and 4.x contexts supported by OS X are forward-compatible, core profile contexts.
10.7 and 10.8 support the following OpenGL versions:
glfw::WindowHint::ContextVersion(3, 2)
10.9 supports the following OpenGL versions
glfw::WindowHint::ContextVersion(3, 2)
glfw::WindowHint::ContextVersion(3, 3)
glfw::WindowHint::ContextVersion(4, 1)
To create an OS X compatible context, the hints should be specified as follows:
glfw.window_hint(glfw::WindowHint::ContextVersion(3, 2)); glfw.window_hint(glfw::WindowHint::OpenGlForwardCompat(true)); glfw.window_hint(glfw::WindowHint::OpenGlProfile(glfw::OpenGlProfileHint::Core));
Resets the window hints previously set by the window_hint
function to
their default values.
Wrapper for glfwDefaultWindowHints
.
pub fn create_window(
&self,
width: u32,
height: u32,
title: &str,
mode: WindowMode<'_>
) -> Option<(Window, Receiver<(f64, WindowEvent)>)>
pub fn create_window(
&self,
width: u32,
height: u32,
title: &str,
mode: WindowMode<'_>
) -> Option<(Window, Receiver<(f64, WindowEvent)>)>
Creates a new window.
Wrapper for glfwCreateWindow
.
Makes the context of the specified window current. If no window is given then the current context is detached.
Wrapper for glfwMakeContextCurrent
.
Wrapper for glfwGetX11Display
Immediately process the received events.
Wrapper for glfwPollEvents
.
pub fn poll_events_unbuffered<F>(&mut self, f: F) where
F: FnMut(WindowId, (f64, WindowEvent)) -> Option<(f64, WindowEvent)>,
pub fn poll_events_unbuffered<F>(&mut self, f: F) where
F: FnMut(WindowId, (f64, WindowEvent)) -> Option<(f64, WindowEvent)>,
Immediately process the received events. The unbuffered variant differs by allowing
inspection of events prior to their associated native callback returning. This also
provides a way to synchronously respond to the event. Events returned by the closure
are delivered to the channel receiver just as if poll_events
was called. Returning
None
from the closure will drop the event.
Wrapper for glfwPollEvents
.
Sleep until at least one event has been received, and then perform the
equivalent of Glfw::poll_events
.
Wrapper for glfwWaitEvents
.
pub fn wait_events_unbuffered<F>(&mut self, f: F) where
F: FnMut(WindowId, (f64, WindowEvent)) -> Option<(f64, WindowEvent)>,
pub fn wait_events_unbuffered<F>(&mut self, f: F) where
F: FnMut(WindowId, (f64, WindowEvent)) -> Option<(f64, WindowEvent)>,
Sleep until at least one event has been received, and then perform the
equivalent of Glfw::poll_events_unbuffered
.
Wrapper for glfwWaitEvents
.
Sleep until at least one event has been received, or until the specified
timeout is reached, and then perform the equivalent of Glfw::poll_events
.
Timeout is specified in seconds.
Wrapper for glfwWaitEventsTimeout
.
pub fn wait_events_timeout_unbuffered<F>(&mut self, timeout: f64, f: F) where
F: FnMut(WindowId, (f64, WindowEvent)) -> Option<(f64, WindowEvent)>,
pub fn wait_events_timeout_unbuffered<F>(&mut self, timeout: f64, f: F) where
F: FnMut(WindowId, (f64, WindowEvent)) -> Option<(f64, WindowEvent)>,
Sleep until at least one event has been received, or until the specified
timeout is reached, and then perform the equivalent of Glfw::poll_events_unbuffered
.
Timeout is specified in seconds.
Wrapper for glfwWaitEventsTimeout
.
Posts an empty event from the current thread to the event queue, causing
wait_events
or wait_events_timeout
to return.
If no windows exist, this function returns immediately.
Wrapper for glfwPostEmptyEvent
.
Returns the current value of the GLFW timer. Unless the timer has been
set using glfw::set_time
, the timer measures time elapsed since GLFW
was initialized.
Wrapper for glfwGetTime
.
Sets the value of the GLFW timer.
Wrapper for glfwSetTime
.
Wrapper for glfwGetTimerValue
.
Wrapper for glfwGetTimerFrequency
Sets the number of screen updates to wait before swapping the buffers of
the current context and returning from Window::swap_buffers
.
Wrapper for glfwSwapInterval
.
Returns true
if the specified OpenGL or context creation API extension
is supported by the current context.
Wrapper for glfwExtensionSupported
.
Wrapper for glfwGetRequiredInstanceExtensions
This function returns a Vector of names of Vulkan instance extensions
required by GLFW for creating Vulkan surfaces for GLFW windows. If successful,
the list will always contains VK_KHR_surface
, so if you don’t require any
additional extensions you can pass this list directly to the VkInstanceCreateInfo
struct.
Will return None
if the API is unavailable.
Returns the address of the specified client API or extension function if it is supported by the current context, NULL otherwise.
Wrapper for glfwGetProcAddress
.
This function returns the address of the specified Vulkan core or extension function for the specified instance. If instance is set to NULL it can return any function exported from the Vulkan loader, including at least the following functions:
vkEnumerateInstanceExtensionProperties
vkEnumerateInstanceLayerProperties
vkCreateInstance
vkGetInstanceProcAddr
If Vulkan is not available on the machine, this function returns NULL
Wrapper for glfwGetInstanceProcAddress
pub fn get_physical_device_presentation_support_raw(
&self,
instance: VkInstance,
device: VkPhysicalDevice,
queue_family: u32
) -> bool
pub fn get_physical_device_presentation_support_raw(
&self,
instance: VkInstance,
device: VkPhysicalDevice,
queue_family: u32
) -> bool
This function returns whether the specified queue family of the specified physical device supports presentation to the platform GLFW was built for.
Wrapper for glfwGetPhysicalDevicePresentationSupport
Constructs a Joystick
handle corresponding to the supplied JoystickId
.
Wrapper for glfwRawMouseMotionSupported
.
Parses the specified ASCII encoded string and updates the internal list with any gamepad
mappings it finds. This string may contain either a single gamepad mapping or many mappings
separated by newlines. The parser supports the full format of the gamecontrollerdb.txt
source file including empty lines and comments.
Wrapper for glfwUpdateGamepadMappings
.
Returns
true
if successful, or false
if an error occurred.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Glfw
impl UnwindSafe for Glfw
Blanket Implementations
Mutably borrows from an owned value. Read more