diff --git a/taichi/rhi/vulkan/vulkan_device.cpp b/taichi/rhi/vulkan/vulkan_device.cpp index c7fffc2a45b2b..4594cf74942f9 100644 --- a/taichi/rhi/vulkan/vulkan_device.cpp +++ b/taichi/rhi/vulkan/vulkan_device.cpp @@ -2787,6 +2787,8 @@ VulkanSurface::~VulkanSurface() { void VulkanSurface::resize(uint32_t width, uint32_t height) { destroy_swap_chain(); + this->width_ = width; + this->height_ = height; create_swap_chain(); } diff --git a/taichi/ui/backends/vulkan/window.cpp b/taichi/ui/backends/vulkan/window.cpp index bc8482fb5936d..f6d27a4d4ca3d 100644 --- a/taichi/ui/backends/vulkan/window.cpp +++ b/taichi/ui/backends/vulkan/window.cpp @@ -27,6 +27,9 @@ void Window::init(Program *prog, const AppConfig &config) { &renderer_->swap_chain(), glfw_window_); fps_limit_ = config.fps_limit; + if (config_.show_window) { + resize(); + } prepare_for_next_frame(); } diff --git a/taichi/ui/common/input_handler.h b/taichi/ui/common/input_handler.h index 78a79dabf369e..e6987c2171ed7 100644 --- a/taichi/ui/common/input_handler.h +++ b/taichi/ui/common/input_handler.h @@ -30,8 +30,11 @@ class InputHandler { first_mouse_ = false; } - last_x_ = xpos; - last_y_ = ypos; + int w, h; + glfwGetWindowSize(window, &w, &h); + + last_x_ = xpos / double(w); + last_y_ = ypos / double(h); for (auto f : user_mouse_pos_callbacks_) { f(xpos, ypos); diff --git a/taichi/ui/common/window_base.cpp b/taichi/ui/common/window_base.cpp index d4fe2468bae4a..7f9434081cd0e 100644 --- a/taichi/ui/common/window_base.cpp +++ b/taichi/ui/common/window_base.cpp @@ -100,10 +100,8 @@ void WindowBase::set_is_running(bool value) { std::pair WindowBase::get_cursor_pos() { CHECK_WINDOW_SHOWING; float x = input_handler_.last_x(); - float y = input_handler_.last_y(); + float y = 1.0 - input_handler_.last_y(); - x = x / (float)config_.width; - y = (config_.height - y) / (float)config_.height; return std::make_pair(x, y); }