Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a fullscreen window using piston?

I was trying to create an application that opens a full-screen window using the piston crate.

How can I retrieve the physical screen size in pixels programmatically? It seems an easy thing to do, but I was not able to figure that out.

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
            });
        }
    }
}
like image 738
Jimmy Hypi Avatar asked Oct 19 '25 01:10

Jimmy Hypi


1 Answers

Seems you can do

    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

funnily I was looking for it for the exact same purpose "the game of life"

like image 128
anvlkv Avatar answered Oct 20 '25 16:10

anvlkv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!