main.cpp 3.2 KB

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