--- layout: default ---
The Rust programming language aims to provide a safe environment, where you can't get any undefined behavior or crash. Glium is a Rust library that aims to push these goals for OpenGL as well.
Its objectives:
use glium::DisplayBuild;
let display = glutin::WindowBuilder::new().build_glium().unwrap();
Glium is based on the Glutin library, which is a pure Rust alternative to
traditional libraries like GLFW, SDL or GLUT. When you call build_glium(),
Glium will build the window and query various informations about the backend.
While Glutin is a partially unsafe library due to the unsafe nature of OpenGL contexts,
Glium on the other hand is totally safe.
The minimal requirements for Glium to start is an OpenGL 2.1 or an OpenGL ES 2 backend.
If these are not met, build_glium returns an Err.
let image_data = File::open(&Path::new("image.png")).unwrap().read_to_end().unwrap();
let image = image::load(image_data, image::PNG).unwrap();
let texture = glium::texture::CompressedTexture2d::new(&display, image);
Glium interacts well with the image library, allowing one to easily load images.
You don't need to worry about client formats, data alignment, immutable storage, etc. Everything is handled automatically.
use glium::texture::UncompressedFloatFormat::U8U8U8U8;
let mut texture = glium::Texture2d::new_empty(display, U8U8U8U8, 1024, 1024);
texture.as_surface().draw(&vertex_buffer, &index_buffer, &program,
&uniforms, ¶ms).unwrap();
Drawing on a texture is as easy as calling texture.as_surface(). Glium
provides easy ways to execute the most common tasks.
If you need some more elaborate features (like a depth or stencil buffer, or multiple
render targets), Glium provides some structs in the framebuffer module.
Open an issue or contact @tomaka on #rust-gamedev