rust - 如何使用活塞创建全屏窗口?
问题描述
我试图创建一个使用活塞板条箱打开全屏窗口的应用程序。
如何以编程方式检索以像素为单位的物理屏幕尺寸?这似乎是一件容易的事,但我无法弄清楚。
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
有趣的是,我在寻找它的目的与“生命游戏”完全相同
推荐阅读
- firebase - 在抛出结果firestore之前等待回调运行
- git - “致命:身份验证失败”与 git-credential-manager
- javascript - 如何使用“ref”属性-EXTJS从父组件访问子组件
- html - 如何将计数器添加到表格顶部而不是底部
- reactjs - 动态 Redux 表单和 MaterializeCSS DatePicker - 如何获取输入的 event.target.name?
- reactjs - 中继棱镜 graphql 更新存储
- java - How to execute sudo commands in Java and get error output?
- python - python中的字母位置
- amazon-s3 - 在 ubuntu 16 上使用 s3fs 自动挂载 S3
- android - Android 构建目标“在 NDK 工具链中找不到工具链”