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

Keystroke to enter fullscreen mode (F11) #9

Closed
satoshinm opened this issue Apr 2, 2017 · 4 comments
Closed

Keystroke to enter fullscreen mode (F11) #9

satoshinm opened this issue Apr 2, 2017 · 4 comments
Labels
Milestone

Comments

@satoshinm
Copy link
Owner

A handy keyboard shortcut to enter into the fullscreen mode. Should work at least on the web version, ideally also native (similar to clicking the maximize button).

Web fullscreen API: https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API

@satoshinm satoshinm added the ui label Apr 2, 2017
@satoshinm satoshinm changed the title Keystroke to enter fullscreen mode Keystroke to enter fullscreen mode (F11) Apr 5, 2017
@satoshinm
Copy link
Owner Author

Fullscreen tests: https://github.com/kripken/emscripten/blob/master/tests/test_html5_fullscreen.c - likely want "stretch" mode. And the "soft fullscreen" ('canvas maximized in the client area of the page') could be a worthwhile default, removing the other widgets in the default shell, delegating for example console output to the browser debugging console (but important to retain downloading/running/etc progress indicators until the emscripten code executes).

However, this demo/test is using emscripten_request_fullscreen(). Is there another API (SDL_SetWindowFullscreen?) working on both native and web?

@satoshinm
Copy link
Owner Author

Craft does have code to enter fullscreen natively, but it's a compile-time constant:

src/config.h:
#define FULLSCREEN 0

src/main.c:
void create_window() {
    int window_width = WINDOW_WIDTH;
    int window_height = WINDOW_HEIGHT;
    GLFWmonitor *monitor = NULL;
    if (FULLSCREEN) {
        int mode_count;
        monitor = glfwGetPrimaryMonitor();
        const GLFWvidmode *modes = glfwGetVideoModes(monitor, &mode_count);
        window_width = modes[mode_count - 1].width;
        window_height = modes[mode_count - 1].height;
    }
    g->window = glfwCreateWindow(
        window_width, window_height, "Craft", monitor, NULL);

http://stackoverflow.com/questions/10253283/glfw-toggling-windowed-fullscreen-mode says "As far as I know you would have to close and reopen this window to switch between a window and fullscreen mode.", so could try resetting g->window (first destroy, then recall create_window()) on GLFW_KEY_F11. But test native #define FULLSCREEN 1 first.

@satoshinm satoshinm added this to the important milestone Apr 9, 2017
@satoshinm
Copy link
Owner Author

satoshinm commented Apr 9, 2017

Testing with #define FULLSCREEN 1, curious behavior. First, since it uses glfwGetVideoModes() and sets window_height and window_width from the monitor dimensions, on a retina display this uses a very high resolution. Second, it shows briefly but blacks out, and I can use hot corners to show the desktop.

http://stackoverflow.com/questions/10253283/glfw-toggling-windowed-fullscreen-mode#10675990 has a good tip, using glfwGetDesktopMode() to query for the current resolution and avoid changing it. However, the other comment refers to glfwOpenWindow (and GLFW_FULLSCREEN), which has been replaced with glfwCreateWindow (and window hints). And glfwGetDesktopMode() replaced by glfwGetVideoMode(): http://www.glfw.org/docs/latest/group__monitor.html


http://www.glfw.org/docs/latest/group__window.html#ga5c336fddf2cbb5b92f65f10fb6043344

Once you have created the window, you can switch it between windowed and full screen mode with glfwSetWindowMonitor. If the window has an OpenGL or OpenGL ES context, it will be unaffected.


There are 20 video modes returned by glfwGetVideoMode() at least on my system, and Craft picks the last, highest-resolution:

0: 640 x 480
1: 840 x 524
2: 800 x 600
3: 960 x 540
4: 960 x 600
5: 1024 x 576
6: 1024 x 768
7: 1280 x 720
8: 1344 x 756
9: 1440 x 810
10: 1280 x 1024
11: 1600 x 900
12: 1600 x 1200
13: 1920 x 1080
14: 2048 x 1152
15: 2560 x 1440
16: 2880 x 1620
17: 3200 x 1800
18: 4096 x 2304
19: 5120 x 2880

5120x2880 is way too high (high-DPI), /2 = 15: 2560x1440 is more reasonable, and changing it manually works -- the game launches fullscreen and is playable. Now the question becomes, how to choose this automatically? There is no "scale factor" in http://www.glfw.org/docs/latest/structGLFWvidmode.html#details and width/height are all in screen coordinates. glfwGetFramebufferSize can be used to get the size in pixels, not screen coordinates, but it is called on a window. rougier/freetype-gl#91 (comment) says the correct way to fix this could be:

query the framebuffer size after window creation, to compute the ratio between window and framebuffer resolution and to resize the window accordingly.

--

Craft has get_scale_factor(), using these glfw calls, but it only operates on an existing window. Create the window naively, then get the scale factor and if not 1, scale it down by said factor? update: did this in 13b538d - works now with #define FULLSCREEN 1, to add the toggle.. continue in #48

@satoshinm
Copy link
Owner Author

Added initial implementation in #48
but see also bug #49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant