Skip to content

Instantly share code, notes, and snippets.

@rpasta42
Last active May 3, 2016 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rpasta42/04c01527e043077771653f942b298567 to your computer and use it in GitHub Desktop.
Save rpasta42/04c01527e043077771653f942b298567 to your computer and use it in GitHub Desktop.
Problem initializing glium and glutin window.
//Hello rusters, I'm writing a rust graphics environment with a custom scripting language using glium.
//As example program, I'm writing a tic-tac-toe game which needs to be able to capture location of mouse clicks.
//I want to find mouse location on screen, and glutin event returns location in pixels.
//But I need location as a ratio of OpenGL display size.
//It appears I can use glium::glutin::Window.get_inner_size_pixels(&self).
//But to initialize glium, it captures WindowBuilder,
// preventing me from building the window.
use glium::glutin::WindowBuilder;
let win_builder = WindowBuilder::new();
let display = win_builder.build_glium().unwrap();
let window = win_builder.build().unwrap(); //causes problem
//...somewhere in the main loop...
let mut mouse_x = 0.0, mouse_y = 0.0;
let polled_events = display.poll_events();
for ev in polled_events {
if let Event::MouseMoved(x, y) = ev {
self.mouse_pos.0 = x as f32;
self.mouse_pos.1 = y as f32;
}
}
let pos_x = mouse_x / window.get_inner_size_pixels().unwrap().0;
let pos_y = mouse_y / window.get_inner_size_pixels().unwrap().1;
//The actual code where I ran into the problem is here:
//https://github.com/KostyaKow/skomakare/blob/master/src/game.rs#L27
//This file is a part of a small graphics environment aimed at teaching Lisp to kids.
//I'm using my own lisp interpreter (https://github.com/KostyaKow/LambdaOxide)
//and it's still in early stages of development but the minimum functionality already works.
//I would love feedback on my coding style, since it's my first rust project.
//Here's an example to draw circle:
//https://github.com/KostyaKow/skomakare/blob/master/circle.lo
//And this is example I started for tictactoe:
//https://github.com/KostyaKow/skomakare/blob/master/tictactoe.lo
@rpasta42
Copy link
Author

rpasta42 commented May 3, 2016

Solved by using GlutinFacade::get_framebuffer_dimensions()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment