我使用Glium编写了一个游戏,在这个游戏中,当检测到单击时,我必须在特定位置呈现图像。要做到这一点,我需要得到X和Y的位置。那我怎么才能拿到呢?
我的当前代码如下:
/* ... */
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,
}如果可能的话,我不介意将OpenGL坐标作为X和Y (-1,1),但我认为将其传递到顶点缓冲区会很麻烦。
发布于 2022-07-12 22:15:02
这就是我一直在寻找的答案,它是一个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 */https://stackoverflow.com/questions/72946404
复制相似问题