min_gl

Crates.iomin_gl
lib.rsmin_gl
version0.3.0
sourcesrc
created_at2022-02-16 20:35:12.109089
updated_at2022-02-19 07:36:36.39124
descriptionMinimal boilerplate code for OpenGL applications with glfw and glad.
homepage
repositoryhttps://github.com/Waistax/min_gl
max_upload_size
id533536
size873,374
Cem GEÇGEL (calestialgem)

documentation

README

min_gl


This is a small library that brings together glfw and glad to handle boilerplate code. The user only needs to create a Display, which initializes and terminates necessary stuff as a smart pointer. Hence, in the lifetime of the Display, OpenGL calls can be freely made without any other setup.


Example

use glfw::WindowEvent;
use min_gl::{gl, Display, Options};

fn main() {
    // Assume this is some application state.
    let mut event_count = 0u32;

    // Just create and done!
    // All library initialization and window creation is handled.
    // They panic if an error occurs.
    let mut disp = Display::new(
        // No defaults; you cannot miss anything!
        Options {
            width: 1280,
            height: 720,
            title: "Display Test".into(),
            fullscreen: false,
            decorated: true,
            msaa: Some(16),
            vsync: true,
        },
        // WindowEvent handling...
        |event| {
            event_count += 1; // Closure can modify state (FnMut).

            match event {
                WindowEvent::Key(k, _, a, _) => println!("Key `{:?}` is {:?}ed!", k, a),
                e => println!("Some {:?} happened!", e),
            }
        },
    );

    // Of course, you can go with more complicated main loops.
    while !disp.window().should_close() {
        // All window events...
        disp.update();

        /* ~~~~ drawing start ~~~~ */

        gl::ClearColor(0.7, 0.5, 0.6, 1.0);

        /* ~~~~ drawing end ~~~~ */

        disp.render();
    }

    // No clean up; thanks to idomatic glfw-rs!
    // OpenGL calls are not valid after `disp` is dropped!
    println!("In total {} window events happened!", event_count);
}

Glad 2 was used with the fallowing options on 16.02.2022:

  • Generator: Rust
  • APIs: gl; Version 4.6 Core
  • Extensions: All
  • Options: None

Perma Link


Copyright (C) 2022 Cem Geçgel gecgelcem@outlook.com

Commit count: 14

cargo fmt