I try to write OpenGL 2.1 / GLSL 1.20.8 compatible code using "gl"

As a pure Rust-noob I finally figured out how to open a window using glutin and gl with an animated background color :tada:

"Ye Olde Notebook" supports OpenGL 2.1 along with a decent shader support of GLSL 1.20.8. So when it came to drawing some fancy triangles I had to figure out, that lots of the older functions like glVertexPointer, glEnableClientState were deprecated and as such had been removed from the current standard.

I have to admit, that I don't really understand Rust's ecosystem around OpenGL. Please correct me, if the following findings are wrong or incomplete:

There's a crate gl whose Homepage link is dead. It seems to be an empty crate whose content should have been generated by gl_generator (when and how?) whose Homepage link is also dead. Those crates (along with khronos_api) seem to belong to a bigger Package(?)/Project(?) gl-rs.

To get started I simply included the following line into my Cargo.toml:

[dependencies]
gl = "*"
glutin = "*"

Is there a simple way to get this running with OpenGL 2.1?
Is there a ready-to-use bindings.rs of older OpenGL versions? Can I generate my own against the development System?

Thanks for any help!

ps: All this gonna be purged as soon as Vulkan kicks in :sunglasses:

1 Like

I read a news item a few days ago about Rpi2 getting hardware OpenGL 2 support so it's reasonable to expect a few more users of Rust and OGL.

Before that it was 1.x via glshim which doesn't even work on ARM at the moment.

Ok, I finally found the cause within gl-rs/gl/build.rs:

Registry::new(Api::Gl, (4, 5), Profile::Core, Fallbacks::All, [])
    .write_bindings(GlobalGenerator, &mut file)
    .unwrap();

The profile and the version to extract have been hard-coded to "GL 4.5 Core" which selects the appropriate items from the Khronos-API-description.

Can I somehow integrate my own demands within my build process?

You can create your own build script in your crate and put the same code as the one you pasted in it.
Then in your main code you import the generated bindings with include!(concat!(env!("OUT_DIR"), "/bindings.rs")); for example.

Everything's explained here: gl-rs/gl_generator at master ยท brendanzab/gl-rs ยท GitHub

1 Like

Thank you for pointing to the documentation I oversaw! I think this answers all my questions.

And general thank for your awesome support in computer graphics!

Note that it is unlikely that Vulkan will work on ye olde notebook, or any machine that doesn't support at least OpenGL 4.

"All this" includes the Notebook :wink:

As soon as I know which hardware and driver supports the whole feature set of Vulkan on both Linux and Windows, a new development workstation will be added to the shopping list.

I got it finally working. There seems to be a driver bug when combining a frustum projection, point sprites and shader computed point sizes. I worked around by using quads textured by a fragment shader:

The documented build script didn't work at all. There seems to to have been some fundamental API changes. The following code worked fine for me:

[code]let mut file = File::create(&Path::new("src").join("gl.rs")).unwrap();

gl_generator::generate_bindings(
GlobalGenerator,
Ns::Gl,
Fallbacks::All,
khronos_api::GL_XML,
vec!,
"2.1",
"core",
&mut file).unwrap();
[/code]

It saves the generated bindings within my project, so my development tools are able to provide code assistance (but most time they time out due to the huge file size).