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 OpenGL
with EGL
. the current glutin API is basically modeled after the OpenGL ES
+ Egl
.
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 isVkInstance
withWSI
(akaVK_HKR_Surface
) extension enabled.NOTE: useful methods are defined in the
GlDisplay
extension trait, which is re-exported from theglutin::prelude
namespace, it is recommended touse glutin::prelude::*;
, similar extension traits are used forContext
,Surface
, etc -
from a
Display
, you enumerate and select a compatibleConfig
, by supply aConfigTemplate
. you may useDefault::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. -
create a
Surface
using the config you selected for each of your windows to be rendered into. it's similar to vulkanVkSurfaceKHR
alternatively, you can create a surface for offline rendering, e.g. rendering into a pixel map
-
create your
Context
, anology toVkDevice
-
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
glium
,glow
, gl_generator, etc. glutin itself doesn't provide bindings for OpenGL functions, but you might need to useget_proc_address
to load the the funciton pointers, e,g, for theglow
crate -
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).