ARTICLE AD BOX
I recently started a game-dev project using only GLFW, GLAD and GLM. Everything was going well till I tried to change my window from a normal 1280x720 window to a (borderless) fullscreen window:
My cursor is visible and functional on other windows, but becomes invisible when on my primary monitor when the game is focused. The cursor still moves properly behind(?) the window, it's just completely invisible.
A friend through Discord screenshare sees the game frozen on the first frame but is able to see my cursor move around, while I see the game perfectly fine but no cursor. No sure what this could mean but perhaps it helps...
Below is the code responsible for the window. This is the only place in the code that does anything with the window. Even though (I think) I'm explicitly setting the cursor to be visible, I can't seem to stop it from hiding when over the focused game window:
#include <GLFW/glfw3.h> class WindowSystem { public: WindowSystem(); ~WindowSystem(); [[nodiscard]] GLFWwindow* getWindow() const { return window; } [[nodiscard]] bool keepWindowOpen() const { return !glfwWindowShouldClose(window); } void windowSwap() const; static int WIDTH; static int HEIGHT; private: GLFWwindow* window; }; #include <iostream> #include <glad/glad.h> #include "systems/core/WindowSystem.hpp" // Defaults int WindowSystem::WIDTH = 1280; int WindowSystem::HEIGHT = 720; WindowSystem::WindowSystem() { if (!glfwInit()) std::cerr << "Failed to initialize GLFW" << std::endl; glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); GLFWmonitor* monitor = glfwGetPrimaryMonitor(); const GLFWvidmode* mode = glfwGetVideoMode(monitor); WIDTH = mode->width; HEIGHT = mode->height; glfwWindowHint(GLFW_RED_BITS, mode->redBits); glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits); glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits); glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate); glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); window = glfwCreateWindow(WIDTH, HEIGHT, "MV_Game", nullptr, nullptr); if (window == nullptr) std::cerr << "Failed to open GLFW window" << std::endl; glfwMakeContextCurrent(window); glfwSetWindowPos(window, 0, 0); glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); if (!gladLoadGLLoader(reinterpret_cast<GLADloadproc>(glfwGetProcAddress))) std::cerr << "Failed to initialize GLAD" << std::endl; } WindowSystem::~WindowSystem() { glfwDestroyWindow(window); glfwTerminate(); } void WindowSystem::windowSwap() const { glfwSwapBuffers(window); glfwPollEvents(); }Functions like glfwGetKey, glfwGetCursorPos and glfwSetMouseButtonCallback work perfectly as expected btw, it's just that the cursor is hidden while explicitly telling it not to be. I've tried everything I could find and am just lost at this point. All that's needed to reproduce (on my pc) is the following main with of course GLFW and GLAD.
#include <memory> #include <GLFW/glfw3.h> #include "systems/core/WindowSystem.hpp" int main() { const auto windowSystem = std::make_unique<WindowSystem>(); while (!glfwWindowShouldClose(windowSystem->getWindow())) { windowSystem->windowSwap(); } }