gpt4 book ai didi

rust - 如何使用 Piston 创建全屏窗口?

转载 作者:行者123 更新时间:2023-12-03 11:27:12 26 4
gpt4 key购买 nike

我试图创建一个使用 Piston 箱打开全屏窗口的应用程序。

如何以编程方式检索物理屏幕尺寸(以像素为单位)?这似乎很容易做到,但我无法弄清楚。

extern crate piston;
extern crate glutin_window;
extern crate graphics;
extern crate opengl_graphics;

use piston::window::WindowSettings;
use piston::event_loop::{Events, EventLoop, EventSettings};
use piston::input::RenderEvent;
use glutin_window::GlutinWindow;
use opengl_graphics::{OpenGL, GlGraphics};

fn main() {
let opengl = OpenGL::V3_2;
// Is there any way to retrieve the screen size programmatically and not to hard code it?
let (screen_width, screen_height) = (1920, 1080);
let settings = WindowSettings::new("The Game Of Life", [screen_width, screen_height])
.graphics_api(opengl)
.fullscreen(true)
.exit_on_esc(true);

let mut window: GlutinWindow = settings.build()
.expect("Could not create window");

let mut events = Events::new(EventSettings::new().lazy(true));
let mut gl = GlGraphics::new(opengl);

while let Some(e) = events.next(&mut window) {
if let Some(args) = e.render_args() {
gl.draw(args.viewport(), |c, g| {
use graphics::{clear};

clear([1.0; 4], g);
//DO STUFF HERE
});
}
}
}

最佳答案

似乎你可以做

    let mut window: Window = WindowSettings::new("spinning-square", [200, 200])
.graphics_api(opengl)
.exit_on_esc(true)
.fullscreen(true)
.build()
.unwrap();

let monitor_id = window.ctx.window().get_current_monitor();
let size = monitor_id.get_dimensions(); // this looks platform dependent
有趣的是,我一直在为“生活游戏”的相同目的寻找它

关于rust - 如何使用 Piston 创建全屏窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58926592/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com