0

I use Glium to write a game where I have to render an image in a specific position when a click is detected. To do so, I need to get the X and Y position. So how do I get them?

My current code looks like this:

/* ... */
event.run(move |event, _, control_flow| {
    match event {
            glutin::event::Event::WindowEvent { event, .. } => match event {
                glutin::event::WindowEvent::CloseRequested => {
                   println!("Received termination signal.");
                  *control_flow = glutin::event_loop::ControlFlow::Exit;
                    return;
                },
                _ => return,
            },
            glutin::event::Event::NewEvents(cause) => match cause {
                glutin::event::StartCause::ResumeTimeReached { .. } => (),
                glutin::event::StartCause::Init => (),
                _ => return,
            },
            _ => return,
        }

If possible, I wouldn't mind getting OpenGL Coordinates as X and Y (-1, 1), but I think it will be a hassle to pass it to a vertex buffer.

AggelosT
  • 108
  • 1
  • 9
  • Can you please publish the whole code (e.g. in a repository, gist, etc.), otherwise I think, we can't help you? The code above is too unrelated to the problem. – AlexN Jul 12 '22 at 06:27
  • What problem, exactly? – AggelosT Jul 12 '22 at 06:39
  • About the coordinates and the click to be recognized. – AlexN Jul 12 '22 at 08:46
  • And what code should I post? I only posted the one I did to make it easier for examples to follow my variable names. Plus the answer is unrelated to the code I posted, I'm looking for something specific to glutin (Probably). – AggelosT Jul 12 '22 at 09:40

1 Answers1

0

This is the answer I was looking for, it's a WindowEvent:

match event {
            glutin::event::Event::WindowEvent { event, .. } => match event {
                glutin::event::WindowEvent::CloseRequested => {
                    println!("Received termination signal.");
                    *control_flow = glutin::event_loop::ControlFlow::Exit;
                    return;
                },
                /* The code to get the mouse position (And print it to the console) */
                glutin::event::WindowEvent::CursorMoved { position, .. } => {
                    println!("Mouse position: {:?}x{:?}", position.x as u16, position.y as u16);
                }
                _ => return,
            },
            /* Handle the rest of events */
AggelosT
  • 108
  • 1
  • 9