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