Expand description
An idiomatic wrapper for the GLFW library.
§Example
extern crate glfw;
use glfw::{Action, Context, Key};
fn main() {
use glfw::fail_on_errors;
let mut glfw = glfw::init(fail_on_errors!()).unwrap();
// Create a windowed mode window and its OpenGL context
let (mut window, events) = glfw.create_window(300, 300, "Hello this is window",
glfw::WindowMode::Windowed) .expect("Failed to create GLFW window.");
// Make the window's context current
window.make_current();
window.set_key_polling(true);
// Loop until the user closes the window
while !window.should_close() {
// Swap front and back buffers
window.swap_buffers();
// Poll for and process events
glfw.poll_events();
for (_, event) in glfw::flush_messages(&events) {
println!("{:?}", event);
match event {
glfw::WindowEvent::Key(Key::Escape, _, Action::Press, _) => {
window.set_should_close(true)
},
_ => {},
}
}
}
}
§Cargo Features
Use the vulkan
feature flag to enable all Vulkan functions and types.
Use the image
feature flag to enable use of the image
library for cursors and icons.
Use the all
feature flag to enable both at the same time.
Re-exports§
pub use self::MouseButton::Button1 as MouseButtonLeft;
pub use self::MouseButton::Button2 as MouseButtonRight;
pub use self::MouseButton::Button3 as MouseButtonMiddle;
Modules§
- ffi
- Low-level function bindings and constants pertaining to the underlying GLFW library.
Macros§
- fail_
on_ errors - A callback that triggers a task failure when an error is encountered.
- log_
errors - A callback that logs each error as it is encountered without triggering a task failure
Structs§
- Cursor
- Represents a window cursor that can be used to display any of the standard cursors or load a custom cursor from an image.
- Debug
Aliases - Formats the type using aliases rather than the default variant names.
- Flushed
Messages - An iterator that yields until no more messages are contained in the
Receiver
’s queue. - Gamepad
State - State of a gamepad.
- Gamma
Ramp - Describes the gamma ramp of a monitor.
- Glfw
- 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. - Glfw
Receiver - Joystick
- A joystick handle.
- Joystick
Hats - Joystick hats.
- Modifiers
- Key modifiers (e.g., Shift, Control, Alt, Super)
- Monitor
- A struct that wraps a
*GLFWmonitor
handle. - PRender
Context - PWindow
- Pixel
Image - When not using the
image
library, or if you just want to, you can specify an image from its raw pixel data using this structure. - Render
Context - A rendering context that can be shared between tasks.
- Thread
Safe Glfw - A struct that represents a thread safe handle to a
Glfw
- Version
- VidMode
- Describes a single video mode.
- Window
- A struct that wraps a
*GLFWwindow
handle.
Enums§
- Action
- Input actions.
- Client
ApiHint - Client API tokens.
- Context
Creation Api - Specifies the API to use to create the context
- Context
Release Behavior ContextReleaseBehavior
specifies the release behavior to be used by the context.- Context
Robustness Hint - Context robustness tokens.
- Cursor
Mode - Cursor modes.
- Error
- Tokens corresponding to various error types.
- Gamepad
Axis - Axis identifier tokens.
- Gamepad
Button - Button identifier tokens.
- Init
Error - An error that might be returned when
glfw::init
is called. - Init
Hint - Initialization hints that can be set using the
init_hint
function. - Joystick
Event - Joystick events.
- Joystick
Id - Joystick identifier tokens.
- Key
- Input keys.
- Monitor
Event - Monitor events.
- Mouse
Button - Mouse buttons. The
MouseButtonLeft
,MouseButtonRight
, andMouseButtonMiddle
aliases are supplied for convenience. - Open
GlProfile Hint - OpenGL profile tokens.
- Standard
Cursor - Standard cursors provided by GLFW
- Swap
Interval - Specifies how the context should handle swapping the buffers.
- Window
Event - Window event messages.
- Window
Hint - Window hints that can be set using the
window_hint
function. - Window
Mode - Describes the mode of a window
Traits§
- Context
- Methods common to renderable contexts
Functions§
- fail_
on_ errors - The function to be used with the
fail_on_errors!()
callback. - flush_
messages - Returns an iterator that yields until no more messages are contained in the
Receiver
’s queue. This is useful for event handling where the blocking behaviour ofReceiver::iter
is undesirable. - get_
error - Wrapper for
glfwGetError
. - get_
error_ string - Wrapper for
glfwGetError
. - get_
key_ name - Wrapper around
glfwGetKeyName
- get_
key_ scancode - Wrapper around
glfwGetKeyScancode
. - get_
version - Wrapper for
glfwGetVersion
. - get_
version_ string - Wrapper for
glfwGetVersionString
. - init
- Initializes the GLFW library. This must be called on the main platform thread.
- init_
hint - Sets hints for the next initialization of GLFW.
- init_
no_ callbacks - key_
name Deprecated - Wrapper around
glfwGetKeyName
- log_
errors - The function to be used with the
LOG_ERRORS
callback. - make_
context_ current - Wrapper for
glfwMakeContextCurrent
. - string_
from_ ⚠c_ str - Replacement for
String::from_raw_buf
- string_
from_ ⚠nullable_ c_ str - Like
string_from_c_str
, but handles null pointers correctly - with_
c_ str - Replacement for
ToCStr::with_c_str