main.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // ImGui - standalone example application for Allegro 5
  2. #include <stdint.h>
  3. #include <allegro5/allegro.h>
  4. #include <allegro5/allegro_primitives.h>
  5. #include <imgui.h>
  6. #include "imgui_impl_a5.h"
  7. int main(int, char**)
  8. {
  9. // Setup Allegro
  10. al_init();
  11. al_install_keyboard();
  12. al_install_mouse();
  13. al_init_primitives_addon();
  14. al_set_new_display_flags(ALLEGRO_RESIZABLE);
  15. ALLEGRO_DISPLAY* display = al_create_display(1280, 720);
  16. al_set_window_title(display, "ImGui Allegro 5 example");
  17. ALLEGRO_EVENT_QUEUE* queue = al_create_event_queue();
  18. al_register_event_source(queue, al_get_display_event_source(display));
  19. al_register_event_source(queue, al_get_keyboard_event_source());
  20. al_register_event_source(queue, al_get_mouse_event_source());
  21. // Setup ImGui binding
  22. ImGui_ImplA5_Init(display);
  23. // Load Fonts
  24. // (see extra_fonts/README.txt for more details)
  25. //ImGuiIO& io = ImGui::GetIO();
  26. //io.Fonts->AddFontDefault();
  27. //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
  28. //io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
  29. //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f);
  30. //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
  31. //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
  32. // Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
  33. //static const ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 }; // will not be copied by AddFont* so keep in scope.
  34. //ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
  35. //io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
  36. //io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
  37. bool show_test_window = true;
  38. bool show_another_window = false;
  39. ImVec4 clear_color = ImColor(114, 144, 154);
  40. // Main loop
  41. bool running = true;
  42. while (running)
  43. {
  44. ALLEGRO_EVENT ev;
  45. while (al_get_next_event(queue, &ev))
  46. {
  47. ImGui_ImplA5_ProcessEvent(&ev);
  48. if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) running = false;
  49. if (ev.type == ALLEGRO_EVENT_DISPLAY_RESIZE)
  50. {
  51. ImGui_ImplA5_InvalidateDeviceObjects();
  52. al_acknowledge_resize(display);
  53. Imgui_ImplA5_CreateDeviceObjects();
  54. }
  55. }
  56. ImGui_ImplA5_NewFrame();
  57. // 1. Show a simple window
  58. // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
  59. {
  60. static float f;
  61. ImGui::Text("Hello, world!");
  62. ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
  63. ImGui::ColorEdit3("clear color", (float*)&clear_color);
  64. if (ImGui::Button("Test Window")) show_test_window ^= 1;
  65. if (ImGui::Button("Another Window")) show_another_window ^= 1;
  66. ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f/ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
  67. }
  68. // 2. Show another simple window, this time using an explicit Begin/End pair
  69. if (show_another_window)
  70. {
  71. ImGui::SetNextWindowSize(ImVec2(200, 100), ImGuiSetCond_FirstUseEver);
  72. ImGui::Begin("Another Window", &show_another_window);
  73. ImGui::Text("Hello");
  74. ImGui::End();
  75. }
  76. // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow()
  77. if (show_test_window)
  78. {
  79. ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver);
  80. ImGui::ShowTestWindow(&show_test_window);
  81. }
  82. // Rendering
  83. al_clear_to_color(al_map_rgba_f(clear_color.x, clear_color.y, clear_color.z, clear_color.w));
  84. ImGui::Render();
  85. al_flip_display();
  86. }
  87. // Cleanup
  88. ImGui_ImplA5_Shutdown();
  89. al_destroy_event_queue(queue);
  90. al_destroy_display(display);
  91. return 0;
  92. }