#windowing #wolf-engine #gamedev #game-engine

wolf_engine_window

A simple, high-level window API for video games

3 releases (breaking)

0.3.0 Aug 12, 2024
0.2.0 Jul 25, 2024
0.1.0 Jul 10, 2024

#969 in Game dev

Download history 94/week @ 2024-07-05 14/week @ 2024-07-12 104/week @ 2024-07-19 50/week @ 2024-07-26 2/week @ 2024-08-02 123/week @ 2024-08-09 17/week @ 2024-08-16

143 downloads per month

MIT/Apache

39KB
808 lines

Wolf Engine Window

Crates.io Crates.io

Provides a simple, high-level window system built on Winit.

Status

This crate is currently in early development. You should expect missing features, bugs, changing APIs, and other spooky stuff until release 1.0.

License

Wolf Engine is licensed under either:

At your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without additional terms or conditions.


lib.rs:

Provides a simple, high-level window system.

Initializing the Window System

Initialize the window system by calling the [init()] function.

let window_context = wolf_engine_window::init().build().unwrap();

Once you've created the EventLoop, you can call its run() method to start the window system with the provided event-handling function.

Handling Events, and Creating Window

#
#
let mut window = None;
window_context.run(|event, context| match event {
    // The main-loop has started.
    // Do intial setup, like creating windows, render surfaces, ext. here.
    Event::Started => {
        println!("Hello, world!");
        window = Some(
            context.create_window(
                WindowSettings::default()
                    .with_title("Example Window")
                    .with_size((800, 600)),
            ).unwrap()
        );
    }
    // All events have been processed.
    Event::EventsCleared => {
        // Start the next frame.
        window.as_ref().unwrap().redraw();
    }
    // Window-specific events.
    Event::WindowEvent(window_id, event) => match event {
        // A window should be redrawn.
        WindowEvent::RedrawRequested => {
            // Render code goes here!
        },
        // A window has / should close.
        WindowEvent::Closed => {
            context.exit(); // Stop the event loop.
        }
        _ => (),
    }
    // The main-loop will stop.
    Event::Exited => println!("Goodbye, World!"),
    _ => (),
});

Drawing on the Window

This crate doesn't provide its own rendering functions. Instead, it implements raw_window_handle traits in order for compatibility with external rendering libraries.

Dependencies

~3–17MB
~250K SLoC