mousePosScale.x=(float)display_w/w;// Some screens e.g. Retina display have framebuffer size != from window size, and mouse inputs are given in window/screen coordinates.
mousePosScale.y=(float)display_h/h;
ImGuiIO&io=ImGui::GetIO();
ImGuiIO&io=ImGui::GetIO();
io.DisplaySize=ImVec2((float)w,(float)h);// Display size, in pixels. For clamping windows positions.
io.DisplaySize=ImVec2((float)display_w,(float)display_h);// Display size, in pixels. For clamping windows positions.
io.DeltaTime=1.0f/60.0f;// Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our timestep is variable)
io.DeltaTime=1.0f/60.0f;// Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our timestep is variable)
io.PixelCenterOffset=0.5f;// Align OpenGL texels
io.PixelCenterOffset=0.5f;// Align OpenGL texels
io.KeyMap[ImGuiKey_Tab]=GLFW_KEY_TAB;// Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array.
io.KeyMap[ImGuiKey_Tab]=GLFW_KEY_TAB;// Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array.
@ -309,9 +302,9 @@ void UpdateImGui()
// (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents())
// (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents())
doublemouse_x,mouse_y;
doublemouse_x,mouse_y;
glfwGetCursorPos(window,&mouse_x,&mouse_y);
glfwGetCursorPos(window,&mouse_x,&mouse_y);
io.MousePos=ImVec2((float)mouse_x,(float)mouse_y);// Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
io.MousePos=ImVec2((float)mouse_x*mousePosScale.x,(float)mouse_y*mousePosScale.y);// Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
io.MouseDown[0]=mousePressed[0]||glfwGetMouseButton(window,GLFW_MOUSE_BUTTON_LEFT)!=0;// If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)",ms_per_frame_avg,1000.0f/ms_per_frame_avg);
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)",ms_per_frame_avg,1000.0f/ms_per_frame_avg);
// Show the ImGui test window
// Most of user example code is in ImGui::ShowTestWindow()
if(show_test_window)
{
ImGui::SetNewWindowDefaultPos(ImVec2(650,20));// Normally user code doesn't need/want to call it because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly!
ImGui::ShowTestWindow(&show_test_window);
}
}
// Show another simple window
// 2. Show another simple window, this time using an explicit Begin/End pair
@ -367,6 +355,13 @@ int main(int argc, char** argv)
ImGui::End();
ImGui::End();
}
}
// 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow()
if(show_test_window)
{
ImGui::SetNewWindowDefaultPos(ImVec2(650,20));// Normally user code doesn't need/want to call this, because positions are saved in .ini file. Here we just want to make the demo initial state a bit more friendly!