main.cpp 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. 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. //ImGuiIO& io = ImGui::GetIO();
  24. //ImFont* my_font0 = io.Fonts->AddFontDefault();
  25. //ImFont* my_font1 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
  26. //ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/Karla-Regular.ttf", 16.0f);
  27. //ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
  28. //ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
  29. //ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese());
  30. bool show_test_window = true;
  31. bool show_another_window = false;
  32. ImVec4 clear_color = ImColor(114, 144, 154);
  33. // Main loop
  34. bool running = true;
  35. while (running)
  36. {
  37. ALLEGRO_EVENT ev;
  38. while (al_get_next_event(queue, &ev))
  39. {
  40. ImGui_ImplA5_ProcessEvent(&ev);
  41. if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) running = false;
  42. }
  43. ImGui_ImplA5_NewFrame();
  44. // 1. Show a simple window
  45. // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
  46. {
  47. static float f;
  48. ImGui::Text("Hello, world!");
  49. ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
  50. ImGui::ColorEdit3("clear color", (float*)&clear_color);
  51. if (ImGui::Button("Test Window")) show_test_window ^= 1;
  52. if (ImGui::Button("Another Window")) show_another_window ^= 1;
  53. ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f/ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
  54. }
  55. // 2. Show another simple window, this time using an explicit Begin/End pair
  56. if (show_another_window)
  57. {
  58. ImGui::SetNextWindowSize(ImVec2(200, 100), ImGuiSetCond_FirstUseEver);
  59. ImGui::Begin("Another Window", &show_another_window);
  60. ImGui::Text("Hello");
  61. ImGui::End();
  62. }
  63. // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow()
  64. if (show_test_window)
  65. {
  66. ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver);
  67. ImGui::ShowTestWindow(&show_test_window);
  68. }
  69. // Rendering
  70. al_clear_to_color(al_map_rgba_f(clear_color.x, clear_color.y, clear_color.z, clear_color.w));
  71. ImGui::Render();
  72. al_flip_display();
  73. }
  74. // Cleanup
  75. ImGui_ImplA5_Shutdown();
  76. al_destroy_event_queue(queue);
  77. al_destroy_display(display);
  78. return 0;
  79. }