Last active
June 18, 2018 22:46
-
-
Save tonyfinn/00c8e1c8ec7636c03a9f653a3b477dd5 to your computer and use it in GitHub Desktop.
Piston Mouse Issues on Intel HD 630
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "mouseonly" | |
version = "0.1.0" | |
authors = ["Tony"] | |
[[bin]] | |
name = "mouseonly" | |
[dependencies] | |
rand = "0.4.2" | |
piston = "0.37.0" | |
pistoncore-glutin_window = "0.47.0" | |
piston2d-opengl_graphics = "0.53.0" | |
[dependencies.piston2d-graphics] | |
version = "0.26.0" | |
features = ["glyph_cache_rusttype"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate piston; | |
extern crate graphics; | |
extern crate glutin_window; | |
extern crate opengl_graphics; | |
extern crate rand; | |
use piston::window::WindowSettings; | |
use piston::event_loop::{ EventSettings, Events }; | |
use piston::input::{ RenderEvent, RenderArgs, MouseCursorEvent }; | |
use glutin_window::GlutinWindow; | |
use opengl_graphics::{ GlGraphics, OpenGL }; | |
use graphics::{clear, rectangle}; | |
const OPENGL_VERSION: OpenGL = OpenGL::V2_1; | |
pub struct App { | |
gl: GlGraphics, // OpenGL drawing backend. | |
cursor_pos: [f64; 2] | |
} | |
impl App { | |
fn new(size: [u32; 2]) -> App { | |
App { | |
gl: GlGraphics::new(OPENGL_VERSION), | |
cursor_pos: [0.0, 0.0] | |
} | |
} | |
fn render(&mut self, args: &RenderArgs) { | |
let context = self.gl.draw_begin(args.viewport()); | |
clear([1.0, 1.0, 1.0, 1.0], &mut self.gl); | |
let [cx, cy] = self.cursor_pos; | |
rectangle([1.0, 0.0, 0.0, 1.0], [cx - 5.0, cy - 5.0, 10.0, 10.0], context.transform, &mut self.gl); | |
self.gl.draw_end(); | |
} | |
fn handle_mouse_move(&mut self, args: [f64; 2]) { | |
self.cursor_pos = args; | |
} | |
} | |
fn main() { | |
let size = [1280, 720]; | |
// Create an Glutin window. | |
let mut window: GlutinWindow = WindowSettings::new( | |
"Mouse Only", | |
size | |
) | |
.opengl(OPENGL_VERSION) | |
.exit_on_esc(true) | |
.vsync(true) | |
.build() | |
.unwrap(); | |
// Create a new game and run it. | |
let mut app = App::new(size); | |
let mut events = Events::new(EventSettings::new()); | |
while let Some(e) = events.next(&mut window) { | |
if let Some(mouse_pos) = e.mouse_cursor_args() { | |
app.handle_mouse_move(mouse_pos); | |
} | |
if let Some(r) = e.render_args() { | |
app.render(&r); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment