main.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // ImGui - standalone example application for Glfw + OpenGL 2, using fixed pipeline
  2. #include <imgui.h>
  3. #include "imgui_impl_glfw.h"
  4. #include <stdio.h>
  5. #include <GLFW/glfw3.h>
  6. static void error_callback(int error, const char* description)
  7. {
  8. fprintf(stderr, "Error %d: %s\n", error, description);
  9. }
  10. int main(int, char**)
  11. {
  12. // Setup window
  13. glfwSetErrorCallback(error_callback);
  14. if (!glfwInit())
  15. exit(1);
  16. GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui OpenGL2 example", NULL, NULL);
  17. glfwMakeContextCurrent(window);
  18. // Setup ImGui binding
  19. ImGui_ImplGlfw_Init(window, true);
  20. //ImGuiIO& io = ImGui::GetIO();
  21. //ImFont* my_font1 = io.Fonts->AddFontDefault();
  22. //ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("extra_fonts/Karla-Regular.ttf", 15.0f);
  23. //ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
  24. //ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
  25. //ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese());
  26. bool show_test_window = true;
  27. bool show_another_window = false;
  28. ImVec4 clear_color = ImColor(114, 144, 154);
  29. // Main loop
  30. while (!glfwWindowShouldClose(window))
  31. {
  32. glfwPollEvents();
  33. ImGui_ImplGlfw_NewFrame();
  34. // 1. Show a simple window
  35. // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
  36. {
  37. static float f;
  38. ImGui::Text("Hello, world!");
  39. ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
  40. ImGui::ColorEdit3("clear color", (float*)&clear_color);
  41. if (ImGui::Button("Test Window")) show_test_window ^= 1;
  42. if (ImGui::Button("Another Window")) show_another_window ^= 1;
  43. ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
  44. }
  45. // 2. Show another simple window, this time using an explicit Begin/End pair
  46. if (show_another_window)
  47. {
  48. ImGui::SetNextWindowSize(ImVec2(200,100), ImGuiSetCond_FirstUseEver);
  49. ImGui::Begin("Another Window", &show_another_window);
  50. ImGui::Text("Hello");
  51. ImGui::End();
  52. }
  53. // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow()
  54. if (show_test_window)
  55. {
  56. ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver);
  57. ImGui::ShowTestWindow(&show_test_window);
  58. }
  59. // Rendering
  60. glViewport(0, 0, (int)ImGui::GetIO().DisplaySize.x, (int)ImGui::GetIO().DisplaySize.y);
  61. glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
  62. glClear(GL_COLOR_BUFFER_BIT);
  63. ImGui::Render();
  64. glfwSwapBuffers(window);
  65. }
  66. // Cleanup
  67. ImGui_ImplGlfw_Shutdown();
  68. glfwTerminate();
  69. return 0;
  70. }