Setup
In order to use OpenGL with Rust (or any other programming language as far as I’ve seen) two libraries are needed:
- A context creation library that creates OpenGL contexts, defines window parameters, and handles user input.
- A OpenGL function pointer loader that binds the OpenGL functions to Rust functions that can be call in our code.
Bwasty’s tutorial uses glfw, however, I’ve chosen to use glutin as it seems to be more Rust oriented in its API calls. This means that the code doesn’t exactly match up, and in fact ends up being quite different.
As for the function pointer loader, I’ll be using gl-rs which allows us to use OpenGL functions with Rust. Without this library, looking up the OS specific function calls in Rust would be way too complicated (and out of my current skillset!).
Luckily, setting both of these up is really easy (bless Cargo), and it’s just a matter of adding the dependencies into the cargo.toml
file, like so:
[dependencies]
glutin = "0.28.0"
gl = "0.10.0"
So with this done, we can start our first OpenGL program.