dependencies/third-party/imgui/src/examples/example_allegro5/main.cpp
Go to the documentation of this file.
1 // dear imgui: standalone example application for Allegro 5
2 // If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp.
3 
4 #include <stdint.h>
5 #include <allegro5/allegro.h>
6 #include <allegro5/allegro_primitives.h>
7 #include "imgui.h"
8 #include "imgui_impl_allegro5.h"
9 
10 int main(int, char**)
11 {
12  // Setup Allegro
13  al_init();
14  al_install_keyboard();
15  al_install_mouse();
16  al_init_primitives_addon();
17  al_set_new_display_flags(ALLEGRO_RESIZABLE);
18  ALLEGRO_DISPLAY* display = al_create_display(1280, 720);
19  al_set_window_title(display, "Dear ImGui Allegro 5 example");
20  ALLEGRO_EVENT_QUEUE* queue = al_create_event_queue();
21  al_register_event_source(queue, al_get_display_event_source(display));
22  al_register_event_source(queue, al_get_keyboard_event_source());
23  al_register_event_source(queue, al_get_mouse_event_source());
24 
25  // Setup Dear ImGui context
28  ImGuiIO& io = ImGui::GetIO(); (void)io;
29  //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
30 
31  // Setup Dear ImGui style
33  //ImGui::StyleColorsClassic();
34 
35  // Setup Platform/Renderer bindings
36  ImGui_ImplAllegro5_Init(display);
37 
38  // Load Fonts
39  // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
40  // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
41  // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
42  // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call.
43  // - Read 'docs/FONTS.txt' for more instructions and details.
44  // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
45  //io.Fonts->AddFontDefault();
46  //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
47  //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
48  //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
49  //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f);
50  //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
51  //IM_ASSERT(font != NULL);
52 
53  bool show_demo_window = true;
54  bool show_another_window = false;
55  ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
56 
57  // Main loop
58  bool running = true;
59  while (running)
60  {
61  // Poll and handle events (inputs, window resize, etc.)
62  // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
63  // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
64  // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
65  // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
66  ALLEGRO_EVENT ev;
67  while (al_get_next_event(queue, &ev))
68  {
70  if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
71  running = false;
72  if (ev.type == ALLEGRO_EVENT_DISPLAY_RESIZE)
73  {
75  al_acknowledge_resize(display);
77  }
78  }
79 
80  // Start the Dear ImGui frame
83 
84  // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
85  if (show_demo_window)
87 
88  // 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window.
89  {
90  static float f = 0.0f;
91  static int counter = 0;
92 
93  ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
94 
95  ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
96  ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
97  ImGui::Checkbox("Another Window", &show_another_window);
98 
99  ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
100  ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
101 
102  if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
103  counter++;
104  ImGui::SameLine();
105  ImGui::Text("counter = %d", counter);
106 
107  ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
108  ImGui::End();
109  }
110 
111  // 3. Show another simple window.
113  {
114  ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
115  ImGui::Text("Hello from another window!");
116  if (ImGui::Button("Close Me"))
117  show_another_window = false;
118  ImGui::End();
119  }
120 
121  // Rendering
122  ImGui::Render();
123  al_clear_to_color(al_map_rgba_f(clear_color.x, clear_color.y, clear_color.z, clear_color.w));
125  al_flip_display();
126  }
127 
128  // Cleanup
131  al_destroy_event_queue(queue);
132  al_destroy_display(display);
133 
134  return 0;
135 }
main
int main(int, char **)
Definition: dependencies/third-party/imgui/src/examples/example_allegro5/main.cpp:10
running
static std::atomic< bool > running
Definition: network.cpp:48
ImVec4::z
float z
Definition: imgui.h:223
ImGui::GetDrawData
IMGUI_API ImDrawData * GetDrawData()
Definition: imgui.cpp:3293
ImGui::Button
IMGUI_API bool Button(const char *label, const ImVec2 &size=ImVec2(0, 0))
Definition: imgui_widgets.cpp:678
ImGui::Render
IMGUI_API void Render()
Definition: imgui.cpp:4222
imgui.h
ImGui::Text
IMGUI_API void Text(const char *fmt,...) IM_FMTARGS(1)
Definition: imgui_widgets.cpp:247
ImGui::SameLine
IMGUI_API void SameLine(float offset_from_start_x=0.0f, float spacing=-1.0f)
Definition: imgui.cpp:6923
ImGui::GetIO
IMGUI_API ImGuiIO & GetIO()
Definition: imgui.cpp:3286
ImGui_ImplAllegro5_NewFrame
void ImGui_ImplAllegro5_NewFrame()
Definition: imgui_impl_allegro5.cpp:400
show_another_window
static bool show_another_window
Definition: dependencies/third-party/imgui/src/examples/example_glut_opengl2/main.cpp:23
ImGui::End
IMGUI_API void End()
Definition: imgui.cpp:6007
ImVec4::y
float y
Definition: imgui.h:223
queue
Definition: wepoll.c:927
ImGui::ShowDemoWindow
IMGUI_API void ShowDemoWindow(bool *p_open=NULL)
Definition: imgui_demo.cpp:208
ImGui_ImplAllegro5_Shutdown
void ImGui_ImplAllegro5_Shutdown()
Definition: imgui_impl_allegro5.cpp:305
ImGui_ImplAllegro5_InvalidateDeviceObjects
void ImGui_ImplAllegro5_InvalidateDeviceObjects()
Definition: imgui_impl_allegro5.cpp:221
ImGui::SliderFloat
IMGUI_API bool SliderFloat(const char *label, float *v, float v_min, float v_max, const char *format="%.3f", float power=1.0f)
Definition: imgui_widgets.cpp:2652
ImGui::DestroyContext
IMGUI_API void DestroyContext(ImGuiContext *ctx=NULL)
Definition: imgui.cpp:3276
clear_color
static ImVec4 clear_color
Definition: dependencies/third-party/imgui/src/examples/example_glut_opengl2/main.cpp:24
ImGui::Checkbox
IMGUI_API bool Checkbox(const char *label, bool *v)
Definition: imgui_widgets.cpp:1008
ImGui_ImplAllegro5_Init
bool ImGui_ImplAllegro5_Init(ALLEGRO_DISPLAY *display)
Definition: imgui_impl_allegro5.cpp:251
ImGui::CreateContext
IMGUI_API ImGuiContext * CreateContext(ImFontAtlas *shared_font_atlas=NULL)
Definition: imgui.cpp:3267
ImVec4::x
float x
Definition: imgui.h:223
void
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
ImGui_ImplAllegro5_CreateDeviceObjects
bool ImGui_ImplAllegro5_CreateDeviceObjects()
Definition: imgui_impl_allegro5.cpp:174
ImGui_ImplAllegro5_RenderDrawData
void ImGui_ImplAllegro5_RenderDrawData(ImDrawData *draw_data)
Definition: imgui_impl_allegro5.cpp:89
ImGui::ColorEdit3
IMGUI_API bool ColorEdit3(const char *label, float col[3], ImGuiColorEditFlags flags=0)
Definition: imgui_widgets.cpp:4242
ImGui::NewFrame
IMGUI_API void NewFrame()
Definition: imgui.cpp:3691
ImGui::Begin
IMGUI_API bool Begin(const char *name, bool *p_open=NULL, ImGuiWindowFlags flags=0)
Definition: imgui.cpp:5397
ImVec4::w
float w
Definition: imgui.h:223
ImGui_ImplAllegro5_ProcessEvent
bool ImGui_ImplAllegro5_ProcessEvent(ALLEGRO_EVENT *ev)
Definition: imgui_impl_allegro5.cpp:325
ImGuiIO
Definition: imgui.h:1414
ImVec4
Definition: imgui.h:221
imgui_impl_allegro5.h
f
GLfloat f
Definition: glcorearb.h:3964
show_demo_window
static bool show_demo_window
Definition: dependencies/third-party/imgui/src/examples/example_glut_opengl2/main.cpp:22
ImGui::StyleColorsDark
IMGUI_API void StyleColorsDark(ImGuiStyle *dst=NULL)
Definition: imgui_draw.cpp:178
IMGUI_CHECKVERSION
#define IMGUI_CHECKVERSION()
Definition: imgui.h:64


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:55