Crates.io | min_gl |
lib.rs | min_gl |
version | 0.3.0 |
source | src |
created_at | 2022-02-16 20:35:12.109089 |
updated_at | 2022-02-19 07:36:36.39124 |
description | Minimal boilerplate code for OpenGL applications with glfw and glad. |
homepage | |
repository | https://github.com/Waistax/min_gl |
max_upload_size | |
id | 533536 |
size | 873,374 |
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.
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:
Copyright (C) 2022 Cem Geçgel gecgelcem@outlook.com