Skip to content

Latest commit

 

History

History
69 lines (56 loc) · 1.85 KB

skipping_the_white_window.md

File metadata and controls

69 lines (56 loc) · 1.85 KB

Skipping The White Window

When we start a new window, we often see a white window before the scene is ready. This white window remains for a longer time if we have a 3D scene. We can play a trick and skip (or hide) the white window.

First, we hide the window. (See Initializing A Different Window for how to change window.) We set the visible of the window to false.

App::new()
    .add_plugins(DefaultPlugins.set(WindowPlugin {
        primary_window: Some(Window {
            visible: false,
            ..default()
        }),
        ..default()
    }))

When the GPU is ready, we set the visible of the window back to true.

fn make_visible(mut window: Query<&mut Window>, frame_count: Res<FrameCount>) {
    if frame_count.0 == 3 {
        window.single_mut().visible = true;
    }
}

We use a resource FrameCount. Usually, the GPU will be ready after 3 frames.

The full code is as follows:

use bevy::app::{PluginGroup, Update};
use bevy::core::FrameCount;
use bevy::ecs::system::{Query, Res};
use bevy::utils::default;
use bevy::window::{Window, WindowPlugin};
use bevy::{app::App, DefaultPlugins};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins.set(WindowPlugin {
            primary_window: Some(Window {
                visible: false,
                ..default()
            }),
            ..default()
        }))
        .add_systems(Update, make_visible)
        .run();
}

fn make_visible(mut window: Query<&mut Window>, frame_count: Res<FrameCount>) {
    if frame_count.0 == 3 {
        window.single_mut().visible = true;
    }
}

By running the program, we can see that everything is ready when the window appears.

📘 Back: Table of contents