Struct glfw::Glfw[src]
pub struct Glfw { // some fields omitted }
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. The context can be safely cloned or implicitly copied if need be
for convenience.
Methods
impl Glfw
fn set_error_callback<UserData: 'static>(&self, callback: Option<ErrorCallback<UserData>>)
Sets the error callback, overwriting the previous one stored.
Example
use std::cell::Cell; fn error_callback(_: glfw::Error, description: ~str, error_count: &Cell<uint>) { error!("GLFW error {}: {}", error_count.get(), description); error_count.set(error_count.get() + 1); } // sets a new callback glfw.set_error_callback(Some( glfw::Callback { f: error_callback, data: Cell::new(0), } )); // removes the previously set callback glfw.set_error_callback(None);
The FAIL_ON_ERRORS
and LOG_ERRORS
callbacks are provided for
convenience. For example:
// triggers a task failure when a GLFW error is encountered. glfw.set_error_callback(glfw::FAIL_ON_ERRORS);
fn set_monitor_callback<UserData: 'static>(&self, callback: Option<MonitorCallback<UserData>>)
Sets the monitor callback, overwriting the previous one stored.
fn with_primary_monitor<T>(&self, f: |Option<&Monitor>| -> T) -> 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.
Wrapper for glfwGetPrimaryMonitor
.
fn with_connected_monitors<T>(&self, f: |&[Monitor]| -> T) -> T
Supplies a vector of the currently connected monitors to the closure provided.
Wrapper for glfwGetMonitors
.
fn window_hint(&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::ContextVersion(3, 2)
10.9 supports the following OpenGL versions
glfw::ContextVersion(3, 2)
glfw::ContextVersion(3, 3)
glfw::ContextVersion(4, 1)
To create an OS X compatible context, the hints should be specified as follows:
glfw.window_hint(glfw::ContextVersion(3, 2)); glfw.window_hint(glfw::OpenglForwardCompat(true)); glfw.window_hint(glfw::OpenglProfile(glfw::OpenGlCoreProfile));
fn default_window_hints(&self)
Resets the window hints previously set by the window_hint
function to
their default values.
Wrapper for glfwDefaultWindowHints
.
fn create_window(&self, width: u32, height: u32, title: &str, mode: WindowMode) -> Option<(Window, Receiver<(f64, WindowEvent)>)>
Creates a new window.
Wrapper for glfwCreateWindow
.
fn make_context_current(&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
.
fn poll_events(&self)
Immediately process the received events.
Wrapper for glfwPollEvents
.
fn wait_events(&self)
Sleep until at least one event has been recieved, and then perform the
equivalent of Glfw::poll_events
.
Wrapper for glfwWaitEvents
.
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
.
fn set_time(&self, time: f64)
Sets the value of the GLFW timer.
Wrapper for glfwSetTime
.
fn set_swap_interval(&self, interval: u32)
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
.
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
.
fn get_proc_address(&self, procname: &str) -> Option<GLProc>
Returns the address of the specified client API or extension function if it is supported by the current context.
Wrapper for glfwGetProcAddress
.
fn get_joystick(&self, id: JoystickId) -> Joystick
Constructs a Joystick
handle corresponding to the supplied JoystickId
.