LearnWebGPU icon indicating copy to clipboard operation
LearnWebGPU copied to clipboard

Build with GLFW Wayland

Open RickStanley opened this issue 1 year ago • 2 comments

In the "Opening a window" chapter, it is provided a minimal example of opening a window with GLFW.

On Linux, GLFW uses X11 by default, but it's possible to compile the project with Wayland enabled. The following is necessary to achieve this:

  1. Set GLFW_USE_WAYLAND option when creating the build folder: cmake . -B build -D GLFW_USE_WAYLAND=1;
  2. add glfwMakeContextWindow(window); after if (!window) { /* error hanling */ };
  3. add glfwSwapBuffers(window); inside the main loop (while (!glfwWindowShouldClose(window)) { /* loop contents*/ }, usually it's before glfwPollEvents(););

That's it. The official example from the documentation is an ideal minimal code that works both in X11 and Wayland: https://www.glfw.org/documentation.html.

I felt it was important to bring this to attention because of many news on Linux ecosystem:

RickStanley avatar Oct 18 '23 14:10 RickStanley