2个版本

0.1.1 2019年11月6日
0.1.0 2019年11月6日

#950 in 游戏开发

MIT许可证

8KB
76

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

Miru Gl

为个人游戏引擎提供的OpenGL绑定

概述

这个crate旨在用于Miru项目,但也可以独立使用。

需要注意的是,Miru被固定在最低OpenGL核心版本3.3,以保持尽可能简单,同时与大多数现代硬件兼容。

API与gl-rs非常相似,这得益于其gl_generator crate,但使用了Struct Generator

MiruGl类型薄包装生成的Gl结构体。

目前,它使用Rc来确保OpenGL上下文不会跨线程边界传递,同时避免处理生命周期。

使用

[dependencies]
miru-gl = "0.1"

使用glutin创建具有OpenGL上下文的窗口

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);
}

无运行时依赖

~105KB