Crate glfw[−][src]
An idiomatic wrapper for the GLFW library.
Example
extern crate glfw; use glfw::{Action, Context, Key}; fn main() { let mut glfw = glfw::init(glfw::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. |
Structs
Callback | |
Cursor | Represents a window cursor that can be used to display any of the standard cursors or load a custom cursor from an image. |
DebugAliases | Formats the type using aliases rather than the default variant names. |
FlushedMessages | An iterator that yields until no more messages are contained in the
|
GamepadState | State of a gamepad. |
GammaRamp | Describes the gamma ramp of a monitor. |
Glfw | A token from which to call various GLFW functions. It can be obtained by
calling the |
Joystick | A joystick handle. |
JoystickHats | Joystick hats. |
Modifiers | Key modifiers (e.g., Shift, Control, Alt, Super) |
Monitor | A struct that wraps a |
PixelImage | When not using the |
RenderContext | A rendering context that can be shared between tasks. |
VidMode | Describes a single video mode. |
Window | A struct that wraps a |
Enums
Action | Input actions. |
ClientApiHint | Client API tokens. |
ContextCreationApi | Specifies the API to use to create the context |
ContextReleaseBehavior |
|
ContextRobustnessHint | Context robustness tokens. |
CursorMode | Cursor modes. |
Error | Tokens corresponding to various error types. |
GamepadAxis | Axis identifier tokens. |
GamepadButton | Button identifier tokens. |
InitError | An error that might be returned when |
InitHint | Initialization hints that can be set using the |
JoystickEvent | Joystick events. |
JoystickId | Joystick identifier tokens. |
Key | Input keys. |
MonitorEvent | Monitor events. |
MouseButton | Mouse buttons. The |
OpenGlProfileHint | OpenGL profile tokens. |
StandardCursor | Standard cursors provided by GLFW |
SwapInterval | Specifies how the context should handle swapping the buffers. |
WindowEvent | Window event messages. |
WindowHint | Window hints that can be set using the |
WindowMode | Describes the mode of a window |
Statics
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. |
Traits
Context | Methods common to renderable contexts |
Functions
fail_on_errors | The function to be used with the |
flush_messages | Returns an iterator that yields until no more messages are contained in the
|
get_key_name | Wrapper around ’glfwGetKeyName` |
get_key_scancode | Wrapper around |
get_version | Wrapper for |
get_version_string | Wrapper for |
init | Initializes the GLFW library. This must be called on the main platform thread. |
init_hint | Sets hints for the next initialization of GLFW. |
key_name | Deprecated Wrapper around ’glfwGetKeyName` |
log_errors | The function to be used with the |
make_context_current | Wrapper for |
string_from_c_str⚠ | Replacement for |
string_from_nullable_c_str⚠ | Like |
with_c_str | Replacement for |
Type Definitions
ErrorCallback | An error callback. This can be supplied with some user data to be passed to the callback function when it is triggered. |
GLProc | An OpenGL process address. |
JoystickCallback | An joystick callback. This can be supplied with some user data to be passed to the callback function when it is triggered. |
MonitorCallback | An monitor callback. This can be supplied with some user data to be passed to the callback function when it is triggered. |
Scancode | Keyboard code returned by the OS |
WindowId | Unique identifier for a |