fix: fixed ImGui integration
This commit is contained in:
parent
3eb73af274
commit
d1b444bcef
1 changed files with 12 additions and 17 deletions
29
main.cpp
29
main.cpp
|
@ -19,6 +19,7 @@
|
|||
|
||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||
void processInput(GLFWwindow *window);
|
||||
void keyboard_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||
void mouse_pos_callback(GLFWwindow* window, double xpos, double ypos);
|
||||
void mouse_button_callback(GLFWwindow* window, int button, int action, int mods);
|
||||
void mouse_scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
||||
|
@ -55,6 +56,7 @@ int main()
|
|||
}
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
glfwSetKeyCallback(window, keyboard_callback);
|
||||
glfwSetCursorPosCallback(window, mouse_pos_callback);
|
||||
glfwSetMouseButtonCallback(window, mouse_button_callback);
|
||||
glfwSetScrollCallback(window, mouse_scroll_callback);
|
||||
|
@ -79,7 +81,7 @@ int main()
|
|||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange;
|
||||
ImGui::StyleColorsDark();
|
||||
ImGui_ImplGlfw_InitForOpenGL(window, false);
|
||||
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
||||
ImGui_ImplOpenGL3_Init("#version 330 core");
|
||||
|
||||
Shader ourShader("resources/shaders/vert.glsl", "resources/shaders/frag.glsl");
|
||||
|
@ -102,9 +104,10 @@ int main()
|
|||
lastFrame = currentFrame;
|
||||
|
||||
glfwPollEvents();
|
||||
processInput(window);
|
||||
|
||||
if (mouseCaptured || !io.WantCaptureMouse)
|
||||
processInput(window);
|
||||
if (mouseCaptured)
|
||||
io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
|
||||
|
||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
@ -195,13 +198,15 @@ void processInput(GLFWwindow *window)
|
|||
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS && mouseCaptured)
|
||||
camera.ProcessKeyboard(RIGHT, deltaTime);
|
||||
|
||||
if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS && !mouseCaptured)
|
||||
if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS && !mouseCaptured && !ImGui::GetIO().WantCaptureMouse)
|
||||
{
|
||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
mouseCaptured = true;
|
||||
}
|
||||
}
|
||||
|
||||
void keyboard_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {}
|
||||
|
||||
void mouse_pos_callback(GLFWwindow* window, double xposIn, double yposIn)
|
||||
{
|
||||
float xpos = static_cast<float>(xposIn);
|
||||
|
@ -220,19 +225,9 @@ void mouse_pos_callback(GLFWwindow* window, double xposIn, double yposIn)
|
|||
lastX = xpos;
|
||||
lastY = ypos;
|
||||
|
||||
if (mouseCaptured){
|
||||
if (mouseCaptured)
|
||||
camera.ProcessMouseMovement(xoffset, yoffset);
|
||||
ImGui_ImplGlfw_CursorPosCallback(window, -FLT_MAX, -FLT_MAX);
|
||||
} else
|
||||
ImGui_ImplGlfw_CursorPosCallback(window, xpos, ypos);
|
||||
}
|
||||
|
||||
void mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
|
||||
{
|
||||
ImGui_ImplGlfw_MouseButtonCallback(window, button, action, mods);
|
||||
}
|
||||
|
||||
void mouse_scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
|
||||
{
|
||||
ImGui_ImplGlfw_ScrollCallback(window, xoffset, yoffset);
|
||||
}
|
||||
void mouse_button_callback(GLFWwindow* window, int button, int action, int mods) {}
|
||||
void mouse_scroll_callback(GLFWwindow* window, double xoffset, double yoffset) {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue