I can not seem to find good tutorials for the rust glutin crate, (which is made form opengl) their aren't any docs at there that strike me, the official docs are pretty bad as well.
unfortunately, there's indeed lack good documentation to get start with glutin. personally I feel the documents are written with the assumption that the users are familiar with how to use
EGL. the current glutin API is basically modeled after the
OpenGL ES +
in fact, it helps to understand the concepts if you know a little bit of newer APIs like vulkan. in short:
first of all, you create a
Display, which serves as the connection between your application and the platform, anology is
VK_HKR_Surface) extension enabled.
NOTE: useful methods are defined in the
GlDisplayextension trait, which is re-exported from the
glutin::preludenamespace, it is recommended to
use glutin::prelude::*;, similar extension traits are used for
Display, you enumerate and select a compatible
Config, by supply a
ConfigTemplate. you may use
Default::default()if you don't have specific requirements, or configure your to suit your needs (e.g. multisampling) using a ConfigTemplateBuilder`, vulkan anology is selecting physical devices by enumerate their properties.
Surfaceusing the config you selected for each of your windows to be rendered into. it's similar to vulkan
alternatively, you can create a surface for offline rendering, e.g. rendering into a pixel map
Context, anology to
before rendering, don't forget to set one surface as the
current surface; there's no vulkan anology here, as vulkan doesn't have a implicit "current" thingy, you must pass the swapchain image (or other offline image) explictly as render target.
Tip: if you only have one window surface, you can make it current after create the context and forget about "setting surface as current".
render like a pro. you can use any OpenGL loader, such as
glow, gl_generator, etc. glutin itself doesn't provide bindings for OpenGL functions, but you might need to use
get_proc_addressto load the the funciton pointers, e,g, for the
after rendering is done, present the back buffer like old school OpenGL does, but explictly for a specific surface.
hope this helps you get started.
also note, since OpenGL platform integration must be done in a platform specific way by its nature, although glutin provided somewhat abastraction, you still need to consider platform specifc requirements, for instance, on Windows, you must have a
RawWindowHandle to create the
Display, otherwise, the
create_context probably will fail, also the
get_proc_address will be useless (it would return
NULL for most of the OpenGL function pointers).
It may be worth considering an alternative API, like the higher-level
wgpu crate. Which abstracts over not only OpenGL, but also Vulkan, Metal, and DirectX. It also has quite good learning resources such as Learn Wgpu.
And because it's a higher-level abstraction, you don't have to worry about managing GPU memory and barriers like you do in Vulkan. Even though its API is heavily inspired by Vulkan.
Bevy uses wgpu for rendering, FWIW.
I have thought of using that
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.