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§
- Low-level function bindings and constants pertaining to the underlying GLFW library.
Macros§
- A callback that triggers a task failure when an error is encountered.
- A callback that logs each error as it is encountered without triggering a task failure
Structs§
- Represents a window cursor that can be used to display any of the standard cursors or load a custom cursor from an image.
- Formats the type using aliases rather than the default variant names.
- An iterator that yields until no more messages are contained in theReceiver’s queue.
- State of a gamepad.
- Describes the gamma ramp of a monitor.
- A token from which to call various GLFW functions. It can be obtained by calling theinitfunction. 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.
- A joystick handle.
- Joystick hats.
- Key modifiers (e.g., Shift, Control, Alt, Super)
- A struct that wraps a*GLFWmonitorhandle.
- When not using theimagelibrary, or if you just want to, you can specify an image from its raw pixel data using this structure.
- A rendering context that can be shared between tasks.
- A struct that represents a thread safe handle to aGlfw
- Describes a single video mode.
- A struct that wraps a*GLFWwindowhandle.
Enums§
- Input actions.
- Client API tokens.
- Specifies the API to use to create the context
- ContextReleaseBehaviorspecifies the release behavior to be used by the context.
- Context robustness tokens.
- Cursor modes.
- Tokens corresponding to various error types.
- Axis identifier tokens.
- Button identifier tokens.
- An error that might be returned whenglfw::initis called.
- Initialization hints that can be set using theinit_hintfunction.
- Joystick events.
- Joystick identifier tokens.
- Input keys.
- Monitor events.
- Mouse buttons. TheMouseButtonLeft,MouseButtonRight, andMouseButtonMiddlealiases are supplied for convenience.
- OpenGL profile tokens.
- Standard cursors provided by GLFW
- Specifies how the context should handle swapping the buffers.
- Window event messages.
- Window hints that can be set using thewindow_hintfunction.
- Describes the mode of a window
Traits§
- Methods common to renderable contexts
Functions§
- The function to be used with thefail_on_errors!()callback.
- Returns an iterator that yields until no more messages are contained in theReceiver’s queue. This is useful for event handling where the blocking behaviour ofReceiver::iteris undesirable.
- Wrapper forglfwGetError.
- Wrapper forglfwGetError.
- Wrapper aroundglfwGetKeyName
- Wrapper aroundglfwGetKeyScancode.
- Wrapper forglfwGetVersion.
- Wrapper forglfwGetVersionString.
- Initializes the GLFW library. This must be called on the main platform thread.
- Sets hints for the next initialization of GLFW.
- key_name Deprecated Wrapper aroundglfwGetKeyName
- The function to be used with theLOG_ERRORScallback.
- Wrapper forglfwMakeContextCurrent.
- Replacement forString::from_raw_buf
- Likestring_from_c_str, but handles null pointers correctly
- Replacement forToCStr::with_c_str
Type Aliases§
- An OpenGL process address.
- Keyboard code returned by the OS
- A Vulkan process address
- Unique identifier for aWindow.