main.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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/DroidSans.ttf", 16.0f);
  28. //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f);
  29. //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
  30. //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
  31. // Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
  32. //ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 };
  33. //ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
  34. //io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
  35. //io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
  36. bool show_test_window = true;
  37. bool show_another_window = false;
  38. ImVec4 clear_color = ImColor(114, 144, 154);
  39. // Main loop
  40. bool running = true;
  41. while (running)
  42. {
  43. ALLEGRO_EVENT ev;
  44. while (al_get_next_event(queue, &ev))
  45. {
  46. ImGui_ImplA5_ProcessEvent(&ev);
  47. if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) running = false;
  48. if (ev.type == ALLEGRO_EVENT_DISPLAY_RESIZE)
  49. {
  50. ImGui_ImplA5_InvalidateDeviceObjects();
  51. al_acknowledge_resize(display);
  52. Imgui_ImplA5_CreateDeviceObjects();
  53. }
  54. }
  55. ImGui_ImplA5_NewFrame();
  56. // 1. Show a simple window
  57. // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
  58. {
  59. static float f;
  60. ImGui::Text("Hello, world!");
  61. ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
  62. ImGui::ColorEdit3("clear color", (float*)&clear_color);
  63. if (ImGui::Button("Test Window")) show_test_window ^= 1;
  64. if (ImGui::Button("Another Window")) show_another_window ^= 1;
  65. ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f/ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
  66. }
  67. // 2. Show another simple window, this time using an explicit Begin/End pair
  68. if (show_another_window)
  69. {
  70. ImGui::SetNextWindowSize(ImVec2(200, 100), ImGuiSetCond_FirstUseEver);
  71. ImGui::Begin("Another Window", &show_another_window);
  72. ImGui::Text("Hello");
  73. ImGui::End();
  74. }
  75. // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow()
  76. if (show_test_window)
  77. {
  78. ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver);
  79. ImGui::ShowTestWindow(&show_test_window);
  80. }
  81. // Rendering
  82. al_clear_to_color(al_map_rgba_f(clear_color.x, clear_color.y, clear_color.z, clear_color.w));
  83. ImGui::Render();
  84. al_flip_display();
  85. }
  86. // Cleanup
  87. ImGui_ImplA5_Shutdown();
  88. al_destroy_event_queue(queue);
  89. al_destroy_display(display);
  90. return 0;
  91. }