4 releases (2 breaking)
0.3.0 | Feb 19, 2022 |
---|---|
0.2.0 | Feb 17, 2022 |
0.1.1 | Feb 17, 2022 |
0.1.0 | Feb 16, 2022 |
#22 in #glfw
1MB
13K
SLoC
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
Copyright (C) 2022 Cem Geçgel gecgelcem@outlook.com
Dependencies
~2MB
~44K SLoC