main.cpp 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // ImGui - standalone example application for Allegro 5
  2. // public domain
  3. #include <stdint.h>
  4. #include <allegro5/allegro.h>
  5. #include <allegro5/allegro_primitives.h>
  6. #include <imgui.h>
  7. #include "imgui_impl_a5.h"
  8. int main(int, char**)
  9. {
  10. // Setup Allegro
  11. al_init();
  12. al_install_keyboard();
  13. al_install_mouse();
  14. al_init_primitives_addon();
  15. al_set_new_display_flags(ALLEGRO_RESIZABLE);
  16. ALLEGRO_DISPLAY* display = al_create_display(1280, 720);
  17. al_set_window_title(display, "ImGui Allegro 5 example");
  18. ALLEGRO_EVENT_QUEUE* queue = al_create_event_queue();
  19. al_register_event_source(queue, al_get_display_event_source(display));
  20. al_register_event_source(queue, al_get_keyboard_event_source());
  21. al_register_event_source(queue, al_get_mouse_event_source());
  22. // Setup ImGui binding
  23. ImGui_ImplA5_Init(display);
  24. //ImGuiIO& io = ImGui::GetIO();
  25. //ImFont* my_font0 = io.Fonts->AddFontDefault();
  26. //ImFont* my_font1 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
  27. //ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/Karla-Regular.ttf", 16.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. bool show_test_window = true;
  32. bool show_another_window = false;
  33. ImVec4 clear_color = ImColor(114, 144, 154);
  34. // Main loop
  35. bool running = true;
  36. while (running)
  37. {
  38. ALLEGRO_EVENT ev;
  39. while (al_get_next_event(queue, &ev))
  40. {
  41. ImGui_ImplA5_ProcessEvent(&ev);
  42. if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) running = false;
  43. if (ev.type == ALLEGRO_EVENT_DISPLAY_RESIZE)
  44. {
  45. ImGui_ImplA5_InvalidateDeviceObjects();
  46. al_acknowledge_resize(display);
  47. Imgui_ImplA5_CreateDeviceObjects();
  48. }
  49. }
  50. ImGui_ImplA5_NewFrame();
  51. // 1. Show a simple window
  52. // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
  53. {
  54. static float f;
  55. ImGui::Text("Hello, world!");
  56. ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
  57. ImGui::ColorEdit3("clear color", (float*)&clear_color);
  58. if (ImGui::Button("Test Window")) show_test_window ^= 1;
  59. if (ImGui::Button("Another Window")) show_another_window ^= 1;
  60. ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f/ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
  61. }
  62. // 2. Show another simple window, this time using an explicit Begin/End pair
  63. if (show_another_window)
  64. {
  65. ImGui::SetNextWindowSize(ImVec2(200, 100), ImGuiSetCond_FirstUseEver);
  66. ImGui::Begin("Another Window", &show_another_window);
  67. ImGui::Text("Hello");
  68. ImGui::End();
  69. }
  70. // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow()
  71. if (show_test_window)
  72. {
  73. ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver);
  74. ImGui::ShowTestWindow(&show_test_window);
  75. }
  76. // Rendering
  77. al_clear_to_color(al_map_rgba_f(clear_color.x, clear_color.y, clear_color.z, clear_color.w));
  78. ImGui::Render();
  79. al_flip_display();
  80. }
  81. // Cleanup
  82. ImGui_ImplA5_Shutdown();
  83. al_destroy_event_queue(queue);
  84. al_destroy_display(display);
  85. return 0;
  86. }