main.cpp 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_font0 = io.Fonts->AddFontDefault();
  27. //ImFont* my_font1 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
  28. //ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/Karla-Regular.ttf", 16.0f);
  29. //ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
  30. //ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
  31. //ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese());
  32. bool show_test_window = true;
  33. bool show_another_window = false;
  34. ImVec4 clear_color = ImColor(114, 144, 154);
  35. // Main loop
  36. while (!glfwWindowShouldClose(window))
  37. {
  38. ImGuiIO& io = ImGui::GetIO();
  39. glfwPollEvents();
  40. ImGui_ImplGlfwGL3_NewFrame();
  41. // 1. Show a simple window
  42. // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
  43. {
  44. static float f;
  45. ImGui::Text("Hello, world!");
  46. ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
  47. ImGui::ColorEdit3("clear color", (float*)&clear_color);
  48. if (ImGui::Button("Test Window")) show_test_window ^= 1;
  49. if (ImGui::Button("Another Window")) show_another_window ^= 1;
  50. ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
  51. }
  52. // 2. Show another simple window, this time using an explicit Begin/End pair
  53. if (show_another_window)
  54. {
  55. ImGui::SetNextWindowSize(ImVec2(200,100), ImGuiSetCond_FirstUseEver);
  56. ImGui::Begin("Another Window", &show_another_window);
  57. ImGui::Text("Hello");
  58. ImGui::End();
  59. }
  60. // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow()
  61. if (show_test_window)
  62. {
  63. ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver);
  64. ImGui::ShowTestWindow(&show_test_window);
  65. }
  66. // Rendering
  67. glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
  68. glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
  69. glClear(GL_COLOR_BUFFER_BIT);
  70. ImGui::Render();
  71. glfwSwapBuffers(window);
  72. }
  73. // Cleanup
  74. ImGui_ImplGlfwGL3_Shutdown();
  75. glfwTerminate();
  76. return 0;
  77. }