---
layout: default
---
<div class="section">
<div>
<h2>Introduction</h2>
<p>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.</p>
<p>Its objectives:<ul>
<li>Be 100 % safe to use.</li>
<li>Avoid all OpenGL errors either with compile-time checks or runtime checks.
If an OpenGL error is triggered, then it's a bug.</li>
<li>Provide all the features that core OpenGL provides.</li>
<li>Be compatible with the lowest OpenGL version possible, but still use 4.5 features
if they are available.</li>
<li>Be compatible with both OpenGL and OpenGL ES.</li>
</ul></p>
</div>
</div>
<div id="examples" class="section">
<div>
<h2>Examples</h2>
<h3>Initialization</h3>
<pre><code>use glium::DisplayBuild;
let display = glutin::WindowBuilder::new().build_glium().unwrap();</code></pre>
<p>Glium is based on the Glutin library, which is a pure Rust alternative to
traditional libraries like GLFW, SDL or GLUT. When you call <code>build_glium()</code>,
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.</p>
<p>The minimal requirements for Glium to start is an OpenGL 2.1 or an OpenGL ES 2 backend.
If these are not met, <code>build_glium</code> returns an <code>Err</code>.</p>
<h3>Loading an image into a texture</h3>
<pre><code>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);</code></pre>
<p>Glium interacts well with the <a href="https://github.com/PistonDevelopers/image">image library</a>,
allowing one to easily load images.</p>
<p>You don't need to worry about client formats, data alignment, immutable storage,
etc. Everything is handled automatically.</p>
<h3>Render to texture</h3>
<pre><code>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, &params).unwrap();</code></pre>
<p>Drawing on a texture is as easy as calling <code>texture.as_surface()</code>. Glium
provides easy ways to execute the most common tasks.</p>
<p>If you need some more elaborate features (like a depth or stencil buffer, or multiple
render targets), Glium provides some structs in the <code>framebuffer</code> module.</p>
</div>
</div>
<div id="getting-started" class="section">
<div>
<h2>Getting started</h2>
<p><a href="http://tomaka.github.io/glium/glium/index.html">Link to the documentation</a>.</p>
</div>
</div>
<div id="need-help" class="section">
<div>
<h2>Need help?</h2>
<p><a href="https://github.com/tomaka/glium/issues">Open an issue</a> or contact
<strong>@tomaka</strong> on <em>#rust-gamedev</em></p>
</div>
</div>