Rusty GL
Note: This is a work in progress.
Crate: https://crates.io/crates/rusty_gl
Summary
Very thin wrapper over gl-rs, aiming to make code more "rust-like" and safer, while still allowing the control you have with classic OpenGL code.
Current features
- Vertex buffer objects
- Vertex array objects
- Shaders
- Texture 2D
- Single-tuple struct such as
VAO(GLuint)
to enforce correct OpenGL object type is passed in functions
Tuple Struct
Current tuple structs:
pub struct VBO(GLuint);
for vertex buffer objectspub struct VAO(GLuint);
for vertex array objectspub struct GLTexture(GLuint);
for texture objectspub struct GLShader(GLuint);
for programs/ shader object
These structs have no implemention (assosiated function), they are just there to enforce that the correct OpenGL functions are passed into functions. For example:
let mut vao = gl_gen_vertex_array;
gl_bind_buffer;
would not work, as gl_bind_buffer
expects type struct VBO(GLuint)
, but vao is of type VAO(GLuint)
.
Roadmap
- Framebuffer objects
- Uniform shader variables functions
- More OpenGL functions (Right now there is basically only the minimum!)
Usage
[]
= "0.1.5"
= "0.6.0"
The gl-rs
create (gl
) is still needed for certain things such as window proc address and types (eg GLuint
, GLfloat
etc)
Examples
As mentioned above, this crate aims to be a more rust-like alternative to gl-rs.
For example, code from gl-rs such as:
let mut vao = 0;
let mut vbo = 0;
unsafe
Is instead written like
//Create a vertex array object and a vertex buffer object
let mut vao = gl_gen_vertex_array;
let mut vbo = gl_gen_buffer;
//Generate and bind the VAO
gl_bind_vertex_array;
//Generate and bind the VBO
gl_bind_buffer;
//Buffer the vertex data and tell OpenGL the structure
gl_buffer_data;
gl_enable_vertex_attrib_array;
gl_vertex_attrib_pointer;
Changes include:
- snake_case over PascalCase for function names
- No need for the
unsafe {...}
blocks - Strongly typed enums over the error-prone GLenum (Where you can easily pass the incorrect enum)
- No need to cast types to
std::os::raw::c_void
, rusty-gl will do this for you - No need to cast string to
std::ffi::CString
, rusty-gl will do this for you
More examples
Examples on using this crate can be found in the examples folder: https://github.com/Hopson97/rusty-gl/tree/master/Examples
Run the examples with cargo run
.