nannou-org / nannou

A Creative Coding Framework for Rust.
https://nannou.cc/
6.05k stars 306 forks source link

Window dimensions when in fullscreen mode #898

Open pnevyk opened 2 years ago

pnevyk commented 2 years ago

I am trying to run my app in fullscreen mode and at the same time get the dimensions of the fullscreen window to initialize wgpu::Texture in the model function. However, in the model I seem to get the default dimensions instead of the dimensions of the fullscreen window.

Minimal example:

use nannou::prelude::*;

fn main() {
    nannou::app(model)
        .update(update)
        .simple_window(view)
        .fullscreen() // Turning the app into fullscreen
        .run();
}

struct Model {}

fn model(app: &App) -> Model {
    // How I try to get the fullscreen window dimensions.
    println!("{:?}", app.window_rect());
    println!("{:?}", app.main_window().inner_size_pixels());
    // I want to initialize wgpu::Texture here so I can put it into Model.
    Model {}
}

fn update(app: &App, model: &mut Model, update: Update) {}

fn view(app: &App, model: &Model, frame: Frame) {}

Both prints show values corresponding to 800x600 pixels, which is the size of the window if I don't use fullscreen() method.

I checked the nannou code and at the moment of calling model function the window with fullscreen dimensions should already be available:

https://github.com/nannou-org/nannou/blob/5d2620ecefdf3d8455531cfb0830aa2d25213ace/nannou/src/app.rs#L488-L498

but I didn't dive deeper and don't know anything about windowing and winit.

How can I get the width and height of the fullscreen window in the model function?

pnevyk commented 2 years ago

What works for me is using the size of the primary monitor with app.primary_monitor().unwrap().size(). Interestingly, if I use .size(200, 200) instead of .fullscreen(), the app.window_rect() is as expected.

So this issue is resolved for me and can be closed, but I wonder if this should be mentioned somewhere.