diff --git a/examples/README.txt b/examples/README.txt index f958d526f..f5af693fd 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -4,11 +4,10 @@ I choose to provide Visual Studio 10 .sln files and Makefile for Linux/OSX. Please let me know if they don't work with your setup! You can probably just import the .cpp files into your own system and figure out the linkage from there. - opengl_example/ OpenGL example, using GLFW + fixed pipeline. This is simple and should work for all OpenGL enabled applications. - Prefer following this example since it is the shortest one! + Prefer following this example to learn how ImGui works, because it is the simplest shortest one! opengl3_example/ OpenGL example, using GLFW/GL3W + programmable pipeline. @@ -28,3 +27,6 @@ ios_example/ sdl_opengl_example/ SDL2 + OpenGL example. + +allegro5_example/ + Allegro 5 example. diff --git a/examples/allegro5_example/imgui_impl_a5.cpp b/examples/allegro5_example/imgui_impl_a5.cpp index c02e41e93..e9b2282b6 100644 --- a/examples/allegro5_example/imgui_impl_a5.cpp +++ b/examples/allegro5_example/imgui_impl_a5.cpp @@ -1,7 +1,6 @@ // ImGui Allegro 5 bindings -// by @birthggd -// public domain // https://github.com/ocornut/imgui +// by @birthggd, public domain #include // uint64_t #include // memcpy diff --git a/examples/allegro5_example/imgui_impl_a5.h b/examples/allegro5_example/imgui_impl_a5.h index e799e82af..04d006da0 100644 --- a/examples/allegro5_example/imgui_impl_a5.h +++ b/examples/allegro5_example/imgui_impl_a5.h @@ -1,16 +1,18 @@ -// public domain +// ImGui Allegro 5 bindings +// https://github.com/ocornut/imgui +// by @birthggd, public domain #pragma once struct ALLEGRO_DISPLAY; union ALLEGRO_EVENT; -bool ImGui_ImplA5_Init(ALLEGRO_DISPLAY *disp); -void ImGui_ImplA5_ProcessEvent(ALLEGRO_EVENT *ev); -void ImGui_ImplA5_Shutdown(); +bool ImGui_ImplA5_Init(ALLEGRO_DISPLAY* display); +void ImGui_ImplA5_Shutdown(); +void ImGui_ImplA5_NewFrame(); -void ImGui_ImplA5_NewFrame(); - -bool Imgui_ImplA5_CreateDeviceObjects(); -void ImGui_ImplA5_InvalidateDeviceObjects(); +void ImGui_ImplA5_ProcessEvent(ALLEGRO_EVENT* event); +// Use if you want to reset your rendering device without losing ImGui state. +bool Imgui_ImplA5_CreateDeviceObjects(); +void ImGui_ImplA5_InvalidateDeviceObjects(); diff --git a/examples/allegro5_example/main.cpp b/examples/allegro5_example/main.cpp index 1637b6cd6..9a3617521 100644 --- a/examples/allegro5_example/main.cpp +++ b/examples/allegro5_example/main.cpp @@ -1,3 +1,4 @@ +// ImGui - standalone example application for Allegro 5 // public domain #include @@ -6,75 +7,85 @@ #include #include "imgui_impl_a5.h" -int main(int argc, char **argv) +int main(int, char**) { - ALLEGRO_DISPLAY *disp; - ALLEGRO_EVENT_QUEUE *queue; + // Setup Allegro + al_init(); + al_install_keyboard(); + al_install_mouse(); + al_init_primitives_addon(); + ALLEGRO_DISPLAY* display = al_create_display(1280, 720); + al_set_window_title(display, "ImGui Allegro 5 example"); + ALLEGRO_EVENT_QUEUE* queue = al_create_event_queue(); + al_register_event_source(queue, al_get_display_event_source(display)); + al_register_event_source(queue, al_get_keyboard_event_source()); + al_register_event_source(queue, al_get_mouse_event_source()); - al_init(); - al_install_keyboard(); - al_install_mouse(); + // Setup ImGui binding + ImGui_ImplA5_Init(display); + //ImGuiIO& io = ImGui::GetIO(); + //ImFont* my_font0 = io.Fonts->AddFontDefault(); + //ImFont* my_font1 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f); + //ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/Karla-Regular.ttf", 16.0f); + //ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1; + //ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1; + //ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese()); - al_init_primitives_addon(); - - //al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_DONTCARE); - disp = al_create_display(1280, 800); - - queue = al_create_event_queue(); - al_register_event_source(queue, al_get_display_event_source(disp)); - al_register_event_source(queue, al_get_keyboard_event_source()); - al_register_event_source(queue, al_get_mouse_event_source()); - - ImGui_ImplA5_Init(disp); - - bool show_test_window = true; - bool show_another_window = false; - ImVec4 clear_color = ImColor(114, 144, 154); - - bool running = true; - while (running) { - - ALLEGRO_EVENT ev; - while (al_get_next_event(queue, &ev)) { - ImGui_ImplA5_ProcessEvent(&ev); - if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) running = false; - } - - ImGui_ImplA5_NewFrame(); + bool show_test_window = true; + bool show_another_window = false; + ImVec4 clear_color = ImColor(114, 144, 154); + // Main loop + bool running = true; + while (running) { - static float f; - ImGui::Text("Hello, world!"); - ImGui::SliderFloat("float", &f, 0.0f, 1.0f); - ImGui::ColorEdit3("clear color", (float*)&clear_color); - if (ImGui::Button("Test Window")) show_test_window ^= 1; - if (ImGui::Button("Another Window")) show_another_window ^= 1; - ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f/ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); + ALLEGRO_EVENT ev; + while (al_get_next_event(queue, &ev)) + { + ImGui_ImplA5_ProcessEvent(&ev); + if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) running = false; + } + ImGui_ImplA5_NewFrame(); + // 1. Show a simple window + // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug" + { + static float f; + ImGui::Text("Hello, world!"); + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); + ImGui::ColorEdit3("clear color", (float*)&clear_color); + if (ImGui::Button("Test Window")) show_test_window ^= 1; + if (ImGui::Button("Another Window")) show_another_window ^= 1; + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f/ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); + + } + + // 2. Show another simple window, this time using an explicit Begin/End pair + if (show_another_window) + { + ImGui::SetNextWindowSize(ImVec2(200, 100), ImGuiSetCond_FirstUseEver); + ImGui::Begin("Another Window", &show_another_window); + ImGui::Text("Hello"); + ImGui::End(); + } + + // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow() + if (show_test_window) + { + ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver); + ImGui::ShowTestWindow(&show_test_window); + } + + // Rendering + al_clear_to_color(al_map_rgba_f(clear_color.x, clear_color.y, clear_color.z, clear_color.w)); + ImGui::Render(); + al_flip_display(); } - if (show_another_window) { - ImGui::SetNextWindowSize(ImVec2(200, 100), ImGuiSetCond_FirstUseEver); - ImGui::Begin("Another Window", &show_another_window); - ImGui::Text("Hello"); - ImGui::End(); - } + // Cleanup + ImGui_ImplA5_Shutdown(); + al_destroy_event_queue(queue); + al_destroy_display(display); - if (show_test_window) { - ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver); - ImGui::ShowTestWindow(&show_test_window); - } - - al_clear_to_color(al_map_rgba_f(clear_color.x, clear_color.y, clear_color.z, clear_color.w)); - ImGui::Render(); - al_flip_display(); - } - - ImGui_ImplA5_Shutdown(); - - al_destroy_event_queue(queue); - al_destroy_display(disp); - - return 0; + return 0; } -