StudioCherno / Walnut

Walnut is a simple application framework for Vulkan and Dear ImGui apps
MIT License
1.99k stars 367 forks source link

How can I add fullscreen to Walnut #60

Open infinitegame111 opened 9 months ago

infinitegame111 commented 9 months ago

No way of adding fullscreen appears to work for me with walnut, is there a way to do so when the app starts? If so how would I add this so my app will start fullscreened.

VagueLobster commented 9 months ago

You can do something like this:

GLFWmonitor* monitor = glfwGetPrimaryMonitor();

const GLFWvidmode* mode = glfwGetVideoMode(monitor);

glfwWindowHint(GLFW_RED_BITS, mode->redBits);
glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);
glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate);

m_WindowHandle = glfwCreateWindow(fullscreenWidth, fullscreenHeight, "Window Title", monitor, nullptr)

You of course need to call it when creating the window 👍

Acromatic commented 9 months ago

These things always attract the new comers, one thing you should know is the github issues are meant to report bugs, this is not a forum, i realize it doesn't have a forum, perhaps you should buy hazel for a few months and learn some things.

To outline for beginners, do what lobster said, now I'll explain what that is... with any operating system like windows you have what's called "handles" these are the same as like function handles that tie your programming language into the operating systems code, the operating system handles the drivers and hardware, so in order to use any of that you need to follow it's rules and to do so you tie into it's programming.

That brings us to GLFW that is Graphics Layer For Windows.. and when we say graphics we mean "stuff drawn to the screen" windows actual windows, everything that gets drawn in under a window title, that could be custom gui, 3d matrix frames, windows various internal gui systems .... in the case of 3d graphics we need to access the graphics accelerated chip.. the GPU.. and that brings us to OpenGL, Vulkan, DirectX.. they are graphics API's that inform your code of what the hardware graphics card drivers and firmware expect to see from you.

So that is why GLFW (for windows) and Vulkan (for graphics) are used and interact in the manner they do. Now in the case of "fullscreen" there is a windows call to make things fullscreen or you could write one yourself OR.. vulkan might even have one, but likely that's GLFW... because it's going to handle ALL of the "windows handles"... inside of the windows handle, that handles your windows..... so don't get confused.. it's bad naming, yes.

Now ImGui is an application just like yours, it uses lots of OS handlers and GFX handlers like I named before, but walnut only uses GLFW and Vulkan.

In Lobsters example he's asking GLFW to get a handle to the primary monitor device, then he gets the mode which seems to just be a pointer to the current settings so that can be fed back into the GLFW device, there's a couple of empty method names that are either elsewhere in the code or internally trigger fullscreen settings within GLFW, which is also creating a new window, so you would do this initially, inorder for this to work like most games with a toggle however won't work without creating a new window, so you need to throw your entire rendering info into a buffer and pause it inorder to swap it, unless glfw can handle that otherwise... it also won't be borderless fullscreen, you'll need more glfw calls for that if they exist, otherwise you'd have to dig into winRT calls to find the command that makes it vanish, but I believe those are the only 2 steps, because without the title and border you can't move it anyway.