2 releases

✓ Uses Rust 2018 edition

0.1.1 Nov 6, 2019
0.1.0 Nov 6, 2019

#95 in Game development

MIT license

7KB
76 lines

crates.io/license docs.rs crates.io/version

Miru Gl

OpenGL bindings for my personal game engine

Overview

This crate is meant to be used in Miru project, but can be used as a standalone.

It is important to note, that Miru is pinned to minimum OpenGL Core version, which is 3.3, to keep it a simple as possible while also being compatible with most modern hardware.

Api is very similar to gl-rs, thanks to its gl_generator crate, but Struct Generator is used instead.

MiruGl type thinly wraps generated Gl struct.

Currently, it uses Rc to ensure that OpenGL that context isn't transferred across thread bounds, while also avoiding dealing with lifetimes.

Usage

[dependencies]
miru-gl = "0.1"

Creating a window with OpenGL context using glutin:

use glutin;

use miru_gl::MiruGl;

fn main() {
    let el = glutin::EventsLoop::new();
    let wb = glutin::WindowBuilder::new()
        .with_title("Hello world!")
        .with_dimensions(glutin::dpi::LogicalSize::new(800.0, 600.0));
    let windowed_context = glutin::ContextBuilder::new()
    	.with_gl_profile(glutin::GlProfile::Core)
    	.with_gl(glutin::GlRequest::Specific(glutin::Api::OpenGl, (3, 3)))
        .build_windowed(wb, &el)
        .unwrap();
    let windowed_context = unsafe { windowed_context.make_current().unwrap() };

    // the supplied function must be of the type:
    // `&fn(symbol: &'static str) -> *const std::ffi::c_void`
    let gl = MiruGl::load_with(|symbol| windowed_context.get_proc_address(symbol) as *const _);

    println!("{:?}", gl);
}

No runtime deps

~99KB