Crate glfw

source ·
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 the Receiver’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 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.
  • A joystick handle.
  • Joystick hats.
  • Key modifiers (e.g., Shift, Control, Alt, Super)
  • A struct that wraps a *GLFWmonitor handle.
  • 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.
  • A rendering context that can be shared between tasks.
  • A struct that represents a thread safe handle to a Glfw
  • Describes a single video mode.
  • A struct that wraps a *GLFWwindow handle.

Enums§

Traits§

  • Methods common to renderable contexts

Functions§

Type Aliases§

  • An OpenGL process address.
  • Keyboard code returned by the OS
  • Unique identifier for a Window.