Function glfw::init

source ·
pub fn init<T>(callback: T) -> Result<Glfw, InitError>
where T: FnMut(Error, String) + 'static,
Expand description

Initializes the GLFW library. This must be called on the main platform thread.

Wrapper for glfwInit.

§Example

extern crate glfw;

fn main() {
   let glfw = glfw::init_no_callbacks().unwrap();
}

§Error callback

An error callback can be set if desired. This allows for the handling of any errors that occur during initialization. This can subsequently be changed using the glfw::init function.

extern crate glfw;
#[macro_use]
extern crate log;

fn main() {
   let glfw = glfw::init(error_callback).unwrap();
}

fn error_callback(err: glfw::Error, description: String) {
    error!("GLFW error {:?}: {:?}", err, description);
}

§Returns

  • If initialization was successful a Glfw token will be returned along with a Receiver from which errors can be intercepted.
  • Subsequent calls to init will return Glfw token immediately.
  • If an initialization error occurred within the GLFW library Err(InternalInitError) will be returned.