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

Switching to fullscreen doesn't work on Ubuntu #303

Open
tomassedovic opened this issue Dec 15, 2019 · 10 comments
Open

Switching to fullscreen doesn't work on Ubuntu #303

tomassedovic opened this issue Dec 15, 2019 · 10 comments

Comments

@tomassedovic
Copy link
Owner

Originally reported by u/PollenX on Reddit:

https://www.reddit.com/r/rust_gamedev/comments/e9v0x0/tcod_fullscreen_toggle_not_working/

Calling set_fullscreen(true) after the root console has been initialised does not have any effect. This seems to have something to do with the size call in the root console initialiser. When they remove it, they are able to toggle fullscreen.

Here is the root console initialisation code they use:

let mut root = Root::initializer().font("terminal16x16_gs_ro.png", FontLayout::AsciiInRow)
.font_type(FontType::Greyscale)
.size(SCREEN_WIDTH, SCREEN_HEIGHT)
.title("SssBall")
.init();

tcod-rs version: v0.15.0
OS: Ubuntu Linux 19.04

@tomassedovic
Copy link
Owner Author

For what it's worth, I've been unable to reproduce this on my own Linux (Fedora 30) setup with the SDL2-2.0.10-1.fc30.x86_64 and SDL2-devel-2.0.10-1.fc30.x86_64 packages.

Tried the following code (adapted form the keyboard example) on both tcod master and v.0.15.0:

extern crate tcod;

use tcod::{Console, RootConsole, BackgroundFlag};
use tcod::input::Key;
use tcod::input::KeyCode::{Up, Down, Left, Right, Escape, Enter};

fn main() {
    let mut con = RootConsole::initializer()
        .size(80, 50)
        .title("libtcod Rust tutorial")
        .init();

    let mut x = 40;
    let mut y = 25;
    while !con.window_closed() {
        con.clear();
        con.put_char(x, y, '@', BackgroundFlag::Set);
        con.flush();
        let keypress = con.wait_for_keypress(true);
        if keypress.pressed {
            match keypress {
                Key { code: Enter, alt: true, .. } => {
                    println!("pressed Alt+Enter");
                    let fullscreen = con.is_fullscreen();
                    con.set_fullscreen(!fullscreen);
                }
                Key { code: Escape, .. } => break,
                Key { code: Up, .. } => y -= 1,
                Key { code: Down, .. } => y += 1,
                Key { code: Left, .. } => x -= 1,
                Key { code: Right, .. } => x += 1,
                _ => {}
            }
        }
    }
}

Pressing alt+enter toggles the fullscreen off and on just like expected.

@tomassedovic
Copy link
Owner Author

Note, I'm mostly posting this here in hopes that someone else might be willing&able to investigate. I will not be able to do so for quite some time, sorry! :-(

@L3nn0x
Copy link
Collaborator

L3nn0x commented Dec 16, 2019

Just tried it on Windows and it works. The only thing is that it changes the resolution of the screen as well so that might cause a problem for you

@Jacktwist
Copy link

I'm the one with the issue. However it looks like user error because the test code works as expected.

Here's the code repository if anyone is curious to help me spot what I'm doing wrong.

https://github.com/Jacktwist/sssball

@Jacktwist
Copy link

Jacktwist commented Dec 19, 2019

Here's the code I'm using:

let mut root = Root::initializer()
.font("terminal16x16_gs_ro.png", FontLayout::AsciiInRow)
.font_type(FontType::Greyscale)
.size(SCREEN_WIDTH, SCREEN_HEIGHT)
.title("SssBall")
//.fullscreen(true)
.init();

...

let key = root.wait_for_keypress(true);
match key {
Key { code: Enter, alt: true, .. } => {
// Alt+Enter: toggle fullscreen
println!("alt + enter pressed");
root.set_fullscreen(!root.is_fullscreen());
}

@L3nn0x
Copy link
Collaborator

L3nn0x commented Dec 19, 2019

I had a look at your code, and everything is fine. I also downloaded and compiled/ran your whole github repo (the one you linked) and alt+enter works fine. Although the first time I pressed it, it took some time to get out of fullscreen.
I'm using windows 10 with rust v1.37.0

@L3nn0x
Copy link
Collaborator

L3nn0x commented Dec 19, 2019

I tried moving around and then pressing alt+enter and it's fine as well.

@Jacktwist
Copy link

Ok @L3nn0x, thanks for checking it out. I thought I was missing something fundamental about the syntax. I'm using Ubuntu 19. If I comment out the .size() in the initialization, alt + enter works.

@john-science
Copy link

Funny story, I can reproduce this bug on Ubuntu 22.04.

But I tried @Jacktwist 's suggestion, and just commented out the .size() line in the main function. This solves the problem. Except...

  1. It resets the resolution of my monitors on a level I can't even fix via the normal system menus. And nothing short of a reboot fixes it.
  2. The bottom half of the game screen is unrecoverably cut off.

So, that isn't my favorite solution. heh

The bug persists, but it'll be a couple of weeks until I have time to seriously hunt it down.

@softmoth
Copy link

tcod doesn't expose a binding for ffi::TCOD_sys_shutdown(), and doesn't call that function. Thus SDL_Quit is never called to restore the screen resolution. So your screen resolution bug is a separate issue. I think the best fix is probably to use doryen-rs.

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

No branches or pull requests

5 participants