Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLFW Wayland Support #2558

Closed
SaifOwleN opened this issue May 14, 2024 · 8 comments
Closed

GLFW Wayland Support #2558

SaifOwleN opened this issue May 14, 2024 · 8 comments
Labels
Linux Linux specific (any window system) Wayland

Comments

@SaifOwleN
Copy link

For some reason glfw is not using wayland. It's not even giving wayland support

#include <GL/gl.h>
#include <GLFW/glfw3.h>
#include <fmt/core.h>

int main() {
  GLFWwindow *window;
  if (!glfwInit())
    return -1;
  glfwWindowHint(GLFW_SAMPLES, 4);
  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
  glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
  glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
  glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

  if (glfwPlatformSupported(GLFW_PLATFORM_WAYLAND)) {
    glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_WAYLAND);
  } else {
    fmt::println("No Wayland Support");
  }

  window = glfwCreateWindow(800, 800, "GLFW", NULL, NULL);

  if (window == NULL) {
    glfwTerminate();
    return 0;
  }

  glfwMakeContextCurrent(window);

  while (!glfwWindowShouldClose(window)) {
    glfwSwapBuffers(window);
    glfwPollEvents();
  }

  glfwDestroyWindow(window);

  glfwTerminate();
  return 0;
}

It returns No Wayland Support And a window appears but it uses x11 and pitch black.

@dougbinks dougbinks added Wayland Linux Linux specific (any window system) labels Jun 1, 2024
@dougbinks
Copy link
Contributor

Are you certain that Wayland is supported?

a window appears but it uses x11 and pitch black.

If you want another colour try setting glClearColor and then use glClear prior to drawing and swapping buffers..

@SaifOwleN
Copy link
Author

That's my question.
Why is it not supported. The wayland support function returns false.

@dougbinks
Copy link
Contributor

Sorry, I meant are you certain that Wayland is supported by your system?

@dougbinks
Copy link
Contributor

Hi,

It looks like your GLFW library was compiled without Wayland support. The _GLFW_WAYLAND option needs to be defined at compile time.

I also just noticed you are calling the init hint prior to calling init. This should be called prior to the init as follows:

  if (glfwPlatformSupported(GLFW_PLATFORM_WAYLAND)) {
    glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_WAYLAND);
  } else {
    fmt::println("No Wayland Support");
  }
  if (!glfwInit())
    return -1;

@SaifOwleN
Copy link
Author

Sorry, I meant are you certain that Wayland is supported by your system?

Yes, am sure its supported i already use a Wayland wm.

Also i use vcpkg for the library management and here is the cmake command
cmake -DGLFW_USE_WAYLAND=ON ..

and for the hints i fixed it but it still doesn't work

@dougbinks
Copy link
Contributor

What version of GLFW have you got? According to vcpkg it should be 3.4 which is the latest.

GLFW_USE_WAYLAND is now deprecated:
https://github.com/glfw/glfw/blob/master/CMakeLists.txt#L30-L33

@SaifOwleN
Copy link
Author

Thank you it worked

@dougbinks
Copy link
Contributor

Excellent, then I shall mark this as closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Linux Linux specific (any window system) Wayland
Projects
None yet
Development

No branches or pull requests

2 participants