main.cpp 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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: %s\n", description);
  10. }
  11. int main(int argc, char** argv)
  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. ImGui_ImplGlfwGL3_InitFontsTexture();
  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::Begin("Another Window", &show_another_window, ImVec2(200,100));
  56. ImGui::Text("Hello");
  57. ImGui::End();
  58. }
  59. // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow()
  60. if (show_test_window)
  61. {
  62. ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver);
  63. ImGui::ShowTestWindow(&show_test_window);
  64. }
  65. // Rendering
  66. glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
  67. glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
  68. glClear(GL_COLOR_BUFFER_BIT);
  69. ImGui::Render();
  70. glfwSwapBuffers(window);
  71. }
  72. // Cleanup
  73. ImGui_ImplGlfwGL3_Shutdown();
  74. glfwTerminate();
  75. return 0;
  76. }