Convert Figma logo to code with AI

liballeg logoallegro5

The official Allegro 5 git repository. Pull requests welcome!

1,918
291
1,918
386

Top Related Projects

24,437

A simple and easy-to-use library to enjoy videogames programming

10,765

Simple and Fast Multimedia Library

10,902

Simple Directmedia Layer

62,657

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies

5,367

Cinder is a community-developed, free and open source library for professional-quality creative coding in C++.

Quick Overview

Allegro 5 is a cross-platform library for game programming and multimedia applications. It provides low-level routines for creating windows, handling user input, loading data, drawing images, playing sounds, and more. The library is designed to be easy to use for beginners while still offering powerful features for advanced users.

Pros

  • Cross-platform support (Windows, macOS, Linux, iOS, Android)
  • Comprehensive set of features for game development and multimedia applications
  • Active community and regular updates
  • Good documentation and examples

Cons

  • Steeper learning curve compared to some higher-level game engines
  • Limited built-in GUI capabilities
  • Performance may not be as optimized as some platform-specific libraries
  • Smaller ecosystem compared to more popular game development frameworks

Code Examples

  1. Creating a window and drawing a rectangle:
#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>

int main() {
    al_init();
    al_init_primitives_addon();
    
    ALLEGRO_DISPLAY *display = al_create_display(640, 480);
    
    al_clear_to_color(al_map_rgb(0, 0, 0));
    al_draw_filled_rectangle(100, 100, 300, 200, al_map_rgb(255, 0, 0));
    al_flip_display();
    
    al_rest(5.0);
    
    al_destroy_display(display);
    return 0;
}
  1. Handling keyboard input:
#include <allegro5/allegro.h>

int main() {
    al_init();
    al_install_keyboard();
    
    ALLEGRO_DISPLAY *display = al_create_display(640, 480);
    ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();
    
    al_register_event_source(event_queue, al_get_keyboard_event_source());
    
    ALLEGRO_EVENT event;
    while (1) {
        al_wait_for_event(event_queue, &event);
        if (event.type == ALLEGRO_EVENT_KEY_DOWN) {
            if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
                break;
            }
        }
    }
    
    al_destroy_display(display);
    al_destroy_event_queue(event_queue);
    return 0;
}
  1. Playing a sound:
#include <allegro5/allegro.h>
#include <allegro5/allegro_audio.h>
#include <allegro5/allegro_acodec.h>

int main() {
    al_init();
    al_install_audio();
    al_init_acodec_addon();
    
    ALLEGRO_SAMPLE *sample = al_load_sample("sound.wav");
    al_play_sample(sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
    
    al_rest(5.0);
    
    al_destroy_sample(sample);
    return 0;
}

Getting Started

  1. Install Allegro 5 using your package manager or build from source.
  2. Include the necessary headers in your C/C++ file.
  3. Link against the Allegro libraries when compiling.
  4. Initialize Allegro and any required addons.
  5. Create a display, event queue, and other required objects.
  6. Set up your main game loop.
  7. Clean up resources when done.

Example compilation command:

gcc -o mygame mygame.c $(pkg-config --cflags --libs allegro-5 allegro_primitives-5)

Competitor Comparisons

24,437

A simple and easy-to-use library to enjoy videogames programming

Pros of raylib

  • Simpler API and easier learning curve for beginners
  • Built-in support for modern OpenGL and more advanced graphics features
  • More active development and frequent updates

Cons of raylib

  • Less mature and battle-tested compared to Allegro
  • Smaller community and ecosystem of extensions/tools
  • Limited support for older hardware and operating systems

Code Comparison

raylib example:

#include "raylib.h"

int main() {
    InitWindow(800, 450, "raylib example");
    while (!WindowShouldClose()) {
        BeginDrawing();
        ClearBackground(RAYWHITE);
        DrawText("Hello, raylib!", 190, 200, 20, LIGHTGRAY);
        EndDrawing();
    }
    CloseWindow();
    return 0;
}

Allegro 5 example:

#include <allegro5/allegro.h>
#include <allegro5/allegro_font.h>

int main() {
    al_init();
    al_init_font_addon();
    ALLEGRO_DISPLAY *display = al_create_display(800, 450);
    ALLEGRO_FONT *font = al_create_builtin_font();
    al_clear_to_color(al_map_rgb(255, 255, 255));
    al_draw_text(font, al_map_rgb(200, 200, 200), 190, 200, 0, "Hello, Allegro!");
    al_flip_display();
    al_rest(5.0);
    al_destroy_font(font);
    al_destroy_display(display);
    return 0;
}
10,765

Simple and Fast Multimedia Library

Pros of SFML

  • More modern C++ design with object-oriented approach
  • Easier to use and learn, especially for beginners
  • Better support for audio and networking features

Cons of SFML

  • Less cross-platform support compared to Allegro
  • Smaller community and fewer learning resources
  • Limited support for 3D graphics

Code Comparison

SFML example:

#include <SFML/Graphics.hpp>

int main() {
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Window");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);
    
    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed)
                window.close();
        }
        
        window.clear();
        window.draw(shape);
        window.display();
    }
    return 0;
}

Allegro example:

#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>

int main() {
    al_init();
    al_init_primitives_addon();
    ALLEGRO_DISPLAY *display = al_create_display(800, 600);
    
    while (1) {
        al_clear_to_color(al_map_rgb(0, 0, 0));
        al_draw_filled_circle(400, 300, 100, al_map_rgb(0, 255, 0));
        al_flip_display();
    }
    
    al_destroy_display(display);
    return 0;
}
10,902

Simple Directmedia Layer

Pros of SDL

  • Wider platform support, including mobile and web platforms
  • More extensive documentation and community resources
  • Better support for modern graphics APIs like Vulkan and Metal

Cons of SDL

  • Steeper learning curve for beginners
  • Less integrated approach to game development (requires additional libraries for some features)
  • Slightly more complex API for certain tasks

Code Comparison

SDL:

SDL_Init(SDL_INIT_VIDEO);
SDL_Window* window = SDL_CreateWindow("SDL Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0);
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);

Allegro 5:

al_init();
al_create_display(640, 480);
al_clear_to_color(al_map_rgb(0, 0, 0));
al_flip_display();

Both SDL and Allegro 5 are popular multimedia libraries for game development and multimedia applications. SDL offers broader platform support and more extensive documentation, making it suitable for larger projects and cross-platform development. Allegro 5, on the other hand, provides a more integrated approach and simpler API, which can be beneficial for beginners and smaller projects. The code comparison shows that Allegro 5 requires fewer lines of code for basic window creation and rendering, while SDL offers more fine-grained control over the rendering process.

62,657

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies

Pros of ImGui

  • Lightweight and easy to integrate into existing projects
  • Immediate mode GUI, allowing for dynamic and flexible interfaces
  • Extensive documentation and examples

Cons of ImGui

  • Limited to basic UI elements, lacking advanced widgets
  • Requires more manual layout management compared to Allegro's GUI system
  • Less suitable for complex, full-featured applications

Code Comparison

ImGui example:

ImGui::Begin("My Window");
if (ImGui::Button("Click me!"))
    doSomething();
ImGui::End();

Allegro 5 example:

ALLEGRO_EVENT_QUEUE *queue = al_create_event_queue();
al_register_event_source(queue, al_get_display_event_source(display));
al_wait_for_event(queue, &event);
if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN)
    doSomething();

ImGui focuses on immediate mode GUI creation, while Allegro 5 provides a more traditional event-driven approach. ImGui's code is more concise for UI elements, but Allegro 5 offers a broader range of functionality beyond just GUI, including graphics, audio, and input handling.

5,367

Cinder is a community-developed, free and open source library for professional-quality creative coding in C++.

Pros of Cinder

  • More modern C++ design with extensive use of templates and STL
  • Stronger focus on creative coding and multimedia applications
  • Better integration with native OS features and hardware acceleration

Cons of Cinder

  • Steeper learning curve for beginners due to advanced C++ concepts
  • Less cross-platform compatibility compared to Allegro5
  • Smaller community and fewer learning resources available

Code Comparison

Cinder example (drawing a circle):

#include "cinder/app/App.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"

class BasicApp : public ci::app::App {
public:
    void draw() override {
        ci::gl::clear();
        ci::gl::drawSolidCircle(getWindowCenter(), 100);
    }
};

CINDER_APP(BasicApp, ci::app::RendererGl)

Allegro5 example (drawing a circle):

#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>

int main() {
    al_init();
    al_init_primitives_addon();
    ALLEGRO_DISPLAY *display = al_create_display(800, 600);
    al_clear_to_color(al_map_rgb(0, 0, 0));
    al_draw_filled_circle(400, 300, 100, al_map_rgb(255, 255, 255));
    al_flip_display();
    al_rest(5.0);
    return 0;
}

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Welcome to Allegro!

Allegro is a cross-platform library mainly aimed at video game and multimedia programming. It handles common, low-level tasks such as creating windows, accepting user input, loading data, drawing images, playing sounds, etc. and generally abstracting away the underlying platform. However, Allegro is not a game engine: you are free to design and structure your program as you like.

Allegro 5 has the following additional features:

  • Supported on Windows, Linux, Mac OSX, iPhone and Android
  • User-friendly, intuitive C API usable from C++ and many other programming languages
  • Hardware accelerated bitmap and graphical primitive drawing support (via OpenGL or Direct3D)
  • Audio recording support
  • Font loading and drawing
  • Video playback
  • Abstractions over shaders and low-level polygon drawing
  • And more!

This readme contains general information which applies to all platforms that Allegro builds on.

README_cmake.txt discusses some build options for cmake.

README_msvc.txt discusses compilation on Windows with Microsoft Visual C/C++.

README_make.txt discusses compilation with GNU make. This applies to Unix-like operating systems such as Linux, MacOS X and MinGW on Windows.

README_macosx.txt has a few additional notes for MacOS X.

README_iphone.txt discusses iPhone operating systems.

Requirements

We assume you have C and C++ compilers installed and functioning. We support gcc, clang and MSVC.

Allegro also requires CMake 3.0 or later to build. You may download it from http://www.cmake.org/

Library dependencies

Allegro is divided into a core library and a number of addon libraries. The core library depends on certain libraries to function. If you don't have those, nothing will work. These are required for the core library:

  • DirectX SDK (Windows only)

    You can get this for MSVC from the Microsoft web site (large download).

    Alternatively, smaller downloads for MSVC and MinGW are available here: http://liballeg.org/download.html#miscellaneous-files. Some MinGW distributions come with sufficient DirectX SDK to support compiling Allegro.

  • X11 development libraries (Linux/Unix only) The libraries will be part of your Linux distribution, but you may have to install them explicitly.

  • OpenGL development libraries (optional only on Windows)

The addons, too, may require additional libraries. Since the addons are strictly optional, they are not required to build Allegro, but a lot of functionality may be disabled if they are not present.

Windows users may find some precompiled binaries for the additional libraries from http://gnuwin32.sourceforge.net/. You need to get the bin and lib packages. The bin packages contain DLLs, and the lib packages contain the headers and import libraries.

Mac users may find some dependencies in Homebrew, Fink or MacPorts. http://brew.sh/, http://www.finkproject.org/ and http://www.macports.org/

Linux users likely have all the dependencies already, except PhysicsFS and DUMB. If your distribution uses separate development packages, they will need to be installed. The packages are probably named *-dev or *-devel.

These are the dependencies required for the addons:

On Windows it may be a pain to place all these libraries such that they can be found. Please see the README_cmake.txt section on the "deps subdirectory" when the time comes.

API documentation

To build the documentation you will need Pandoc. Pandoc's home page is http://johnmacfarlane.net/pandoc/

Installing Pandoc from source can be challenging, but you can build Allegro without building the documentation.

Online documentation is available on the Allegro web site: http://docs.liballeg.org/

Building with CMake

Building with CMake is a two step process. During the configuration step, cmake will detect your compiler setup and find the libraries which are installed on your system. At the same time, you may select options to customise your build. If you are unsure of what you are doing, leave all the options at the defaults.

You must configure Allegro with a separate build directory. For example,

mkdir build
cd build
cmake ..

If you configure Allegro to build in the source directory (i.e. cmake .) you will get an error message. Delete CMakeCache.txt and the CMakeFiles directory and re-configure as described above.

Once the configuration step is successful, you will invoke another tool to build Allegro. The tool depends on your compiler, but is usually either make, or your IDE.

To avoid problems, unpack Allegro into a directory without spaces or other "weird" characters in the path. This is a known problem.

Now read README_msvc.txt, README_make.txt or README_macosx.txt.