Struct glfw::Glfw

source ·
#[non_exhaustive]
pub struct Glfw { /* private fields */ }
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§

source§

impl Glfw

source

pub fn set_error_callback<T>(&mut self, callback: T)
where T: FnMut(Error, String) + 'static,

Sets the error callback, overwriting the previous one stored.

§Example
// sets a new callback
let mut error_count: usize = 0;
glfw.set_error_callback(Some(move |error, description| {
    println!("GLFW error {}: {}", error_count, description);
    error_count += 1;
}));

// removes the previously set callback
glfw.set_error_callback(None);

The fail_on_errors!() and log_errors!() callback macros are provided for convenience. For example:

// triggers a task failure when a GLFW error is encountered.
glfw.set_error_callback(fail_on_errors!());
source

pub fn unset_error_callback(&mut self)

Unsets the monitor callback

source

pub fn set_monitor_callback<T>(&mut self, callback: T)
where T: FnMut(Monitor, MonitorEvent) + 'static,

Sets the monitor callback, overwriting the previous one stored.

source

pub fn unset_monitor_callback(&mut self)

Unsets the monitor callback

source

pub fn set_joystick_callback<T>(&mut self, callback: T)
where T: FnMut(JoystickId, JoystickEvent) + 'static,

Sets the joystick callback, overwriting the previous one stored

source

pub fn unset_joystick_callback(&mut self)

Unsets the joystick callback

source

pub fn with_primary_monitor<T, F>(&mut self, f: F) -> T
where F: FnOnce(&mut Self, Option<&mut Monitor>) -> T,

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.");
source

pub fn with_window_monitor<T, F>(&mut self, window: &mut Window, f: F) -> T
where F: FnOnce(&mut Self, Option<&mut Monitor>) -> T,

Supplies the window monitor to the closure provided, if it’s fullscreen.

§Example
let (window, events) = glfw.with_window_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.");
source

pub fn with_connected_monitors<T, F>(&mut self, f: F) -> T
where F: FnOnce(&mut Self, &[&mut Monitor]) -> T,

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());
    }
});
source

pub fn window_hint(&mut self, hint: WindowHint)

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));
source

pub fn default_window_hints(&mut self)

Resets the window hints previously set by the window_hint function to their default values.

Wrapper for glfwDefaultWindowHints.

source

pub fn create_window( &mut self, width: u32, height: u32, title: &str, mode: WindowMode<'_> ) -> Option<(PWindow, GlfwReceiver<(f64, WindowEvent)>)>

Creates a new window.

Wrapper for glfwCreateWindow.

source

pub fn make_context_current(&mut self, context: Option<&Window>)

Makes the context of the specified window current. If no window is given then the current context is detached.

Wrapper for glfwMakeContextCurrent.

source

pub fn get_x11_display(&self) -> *mut c_void

Wrapper for glfwGetX11Display

source

pub fn poll_events(&mut self)

Immediately process the received events.

Wrapper for glfwPollEvents.

source

pub fn poll_events_unbuffered<F>(&mut self, f: F)

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.

source

pub fn wait_events(&mut self)

Sleep until at least one event has been received, and then perform the equivalent of Glfw::poll_events.

Wrapper for glfwWaitEvents.

source

pub fn wait_events_unbuffered<F>(&mut self, f: F)

Sleep until at least one event has been received, and then perform the equivalent of Glfw::poll_events_unbuffered.

Wrapper for glfwWaitEvents.

source

pub fn wait_events_timeout(&mut self, timeout: f64)

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.

source

pub fn wait_events_timeout_unbuffered<F>(&mut self, timeout: f64, f: F)

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.

source

pub fn post_empty_event(&self)

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.

source

pub fn get_time(&self) -> f64

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.

source

pub fn set_time(&mut self, time: f64)

Sets the value of the GLFW timer.

Wrapper for glfwSetTime.

source

pub fn get_timer_value(&self) -> u64

Wrapper for glfwGetTimerValue.

source

pub fn get_timer_frequency(&self) -> u64

Wrapper for glfwGetTimerFrequency

source

pub fn set_swap_interval(&mut self, interval: SwapInterval)

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.

source

pub fn extension_supported(&self, extension: &str) -> bool

Returns true if the specified OpenGL or context creation API extension is supported by the current context.

Wrapper for glfwExtensionSupported.

source

pub fn get_proc_address_raw(&self, procname: &str) -> GLProc

Returns the address of the specified client API or extension function if it is supported by the current context, NULL otherwise.

Wrapper for glfwGetProcAddress.

source

pub fn get_joystick(&self, id: JoystickId) -> Joystick

Constructs a Joystick handle corresponding to the supplied JoystickId.

source

pub fn supports_raw_motion(&self) -> bool

Wrapper for glfwRawMouseMotionSupported.

source

pub fn update_gamepad_mappings(&self, mappings: &str) -> bool

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§

source§

impl Clone for Glfw

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Glfw

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for Glfw

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Glfw

§

impl !Send for Glfw

§

impl !Sync for Glfw

§

impl Unpin for Glfw

§

impl UnwindSafe for Glfw

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.