Convert Figma logo to code with AI

raysan5 logoraylib

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

22,183
2,238
22,183
15

Top Related Projects

60,541

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

12,827

A multi-platform library for OpenGL, OpenGL ES, Vulkan, window and input

5,321

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

23,262

Desktop/Android/HTML5/iOS Java game development framework

9,981

Simple and Fast Multimedia Library

Quick Overview

raylib is a simple and easy-to-use library for creating video games and multimedia applications. It is designed to be beginner-friendly while still providing powerful features for more experienced developers. raylib is cross-platform and supports multiple programming languages through bindings.

Pros

  • Simple and intuitive API, making it easy for beginners to get started
  • Cross-platform support (Windows, Linux, macOS, Web, and more)
  • Extensive documentation and examples
  • Active community and regular updates

Cons

  • Limited advanced features compared to some larger game engines
  • Performance may not be as optimized as more specialized libraries
  • Primarily focused on 2D graphics, with limited 3D capabilities
  • Smaller ecosystem compared to more established game development frameworks

Code Examples

  1. Creating a window and drawing a circle:
#include "raylib.h"

int main(void)
{
    InitWindow(800, 450, "raylib [core] example - basic window");

    while (!WindowShouldClose())
    {
        BeginDrawing();
            ClearBackground(RAYWHITE);
            DrawCircle(GetScreenWidth()/2, GetScreenHeight()/2, 50, MAROON);
        EndDrawing();
    }

    CloseWindow();
    return 0;
}
  1. Playing a sound:
#include "raylib.h"

int main(void)
{
    InitWindow(800, 450, "raylib [audio] example - sound loading and playing");
    InitAudioDevice();

    Sound fxWav = LoadSound("resources/sound.wav");

    while (!WindowShouldClose())
    {
        if (IsKeyPressed(KEY_SPACE)) PlaySound(fxWav);

        BeginDrawing();
            ClearBackground(RAYWHITE);
            DrawText("Press SPACE to play sound!", 200, 180, 20, LIGHTGRAY);
        EndDrawing();
    }

    UnloadSound(fxWav);
    CloseAudioDevice();
    CloseWindow();
    return 0;
}
  1. Creating a simple 2D game object:
#include "raylib.h"

typedef struct {
    Vector2 position;
    float radius;
    Color color;
} Ball;

int main(void)
{
    InitWindow(800, 450, "raylib [shapes] example - ball");

    Ball ball = { 0 };
    ball.position = (Vector2){ GetScreenWidth()/2.0f, GetScreenHeight()/2.0f };
    ball.radius = 50;
    ball.color = MAROON;

    while (!WindowShouldClose())
    {
        ball.position.x = GetMouseX();
        ball.position.y = GetMouseY();

        BeginDrawing();
            ClearBackground(RAYWHITE);
            DrawCircleV(ball.position, ball.radius, ball.color);
        EndDrawing();
    }

    CloseWindow();
    return 0;
}

Getting Started

  1. Download raylib from the official website or GitHub repository.
  2. Include the raylib header in your C/C++ project: #include "raylib.h"
  3. Link against the raylib library when compiling.
  4. Use the raylib functions to create your game or application.

Example compilation command (Linux):

gcc -o myprogram myprogram.c -lraylib -lGL -lm -lpthread -ldl -lrt -lX11

For more detailed instructions, refer to the official raylib wiki on GitHub.

Competitor Comparisons

60,541

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

Pros of ImGui

  • Lightweight and easy to integrate into existing projects
  • Highly customizable with a wide range of UI elements
  • Immediate mode GUI, allowing for dynamic and responsive interfaces

Cons of ImGui

  • Limited to 2D interfaces, lacking 3D rendering capabilities
  • Requires more manual layout and positioning compared to Raylib's simplified approach
  • Less comprehensive than Raylib, focusing solely on GUI rather than a full game development framework

Code Comparison

ImGui example:

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

Raylib example:

BeginDrawing();
    ClearBackground(RAYWHITE);
    if (GuiButton((Rectangle){ 100, 100, 120, 30 }, "Click me!"))
        doSomething();
EndDrawing();

Summary

ImGui is a lightweight, immediate mode GUI library ideal for adding user interfaces to existing projects. It offers great flexibility and customization but requires more manual work for layout and positioning. Raylib, on the other hand, provides a more comprehensive game development framework with both 2D and 3D capabilities, including simplified GUI functions. The choice between the two depends on project requirements and the desired level of control over the user interface.

12,827

A multi-platform library for OpenGL, OpenGL ES, Vulkan, window and input

Pros of GLFW

  • More mature and widely adopted in the industry
  • Offers greater flexibility and lower-level control
  • Extensive documentation and community support

Cons of GLFW

  • Steeper learning curve for beginners
  • Requires more boilerplate code to get started
  • Limited to window creation and input handling

Code Comparison

GLFW (basic window creation):

#include <GLFW/glfw3.h>

int main() {
    glfwInit();
    GLFWwindow* window = glfwCreateWindow(640, 480, "GLFW Window", NULL, NULL);
    while (!glfwWindowShouldClose(window)) {
        glfwSwapBuffers(window);
    }
    glfwTerminate();
    return 0;
}

Raylib (basic window creation):

#include "raylib.h"

int main() {
    InitWindow(640, 480, "Raylib Window");
    while (!WindowShouldClose()) {
        BeginDrawing();
        EndDrawing();
    }
    CloseWindow();
    return 0;
}

GLFW focuses on window and input management, requiring additional libraries for graphics rendering. Raylib provides a more comprehensive solution with built-in graphics capabilities, making it easier for beginners to create simple games and applications. However, GLFW's flexibility allows for more advanced customization and integration with other libraries, making it popular among experienced developers and larger projects.

5,321

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

Pros of Cinder

  • More extensive and feature-rich, offering advanced graphics capabilities and integration with modern C++ features
  • Strong support for creative coding and interactive applications, with a focus on artistic and design-oriented projects
  • Robust community and ecosystem, with numerous extensions and add-ons available

Cons of Cinder

  • Steeper learning curve and more complex API compared to Raylib's simplicity
  • Larger codebase and dependencies, potentially leading to longer compilation times and larger executables
  • Less suitable for beginners or those seeking a lightweight, straightforward graphics library

Code Comparison

Cinder example:

#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::Color::gray(0.1f));
        ci::gl::drawSolidCircle(getWindowCenter(), 100);
    }
};

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

Raylib example:

#include "raylib.h"

int main(void) {
    InitWindow(800, 450, "raylib [core] example");
    while (!WindowShouldClose()) {
        BeginDrawing();
        ClearBackground(RAYWHITE);
        DrawCircle(GetScreenWidth()/2, GetScreenHeight()/2, 100, MAROON);
        EndDrawing();
    }
    CloseWindow();
    return 0;
}
23,262

Desktop/Android/HTML5/iOS Java game development framework

Pros of libGDX

  • Cross-platform development for desktop, mobile, and web
  • Rich ecosystem with numerous extensions and tools
  • Mature and well-established framework with extensive documentation

Cons of libGDX

  • Steeper learning curve, especially for beginners
  • Larger codebase and more complex setup compared to Raylib
  • Java-based, which may not be preferred by some developers

Code Comparison

libGDX

public class MyGame extends ApplicationAdapter {
    SpriteBatch batch;
    Texture img;

    @Override
    public void create() {
        batch = new SpriteBatch();
        img = new Texture("badlogic.jpg");
    }
}

Raylib

#include "raylib.h"

int main(void) {
    InitWindow(800, 450, "raylib [core] example");
    Texture2D texture = LoadTexture("resources/logo.png");
    while (!WindowShouldClose()) {
        BeginDrawing();
        DrawTexture(texture, 0, 0, WHITE);
        EndDrawing();
    }
    CloseWindow();
    return 0;
}

Both libraries provide simple ways to create windows and load textures, but Raylib's approach is more straightforward and requires less boilerplate code. libGDX offers more flexibility and object-oriented design, while Raylib focuses on simplicity and ease of use.

9,981

Simple and Fast Multimedia Library

Pros of SFML

  • More mature and feature-rich library with a longer development history
  • Supports a wider range of platforms, including mobile devices
  • Offers a more comprehensive set of multimedia features, including audio and networking

Cons of SFML

  • Larger library size and potentially higher resource usage
  • Steeper learning curve due to more complex API and additional features
  • Less focus on simplicity and ease of use for beginners

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);

Raylib example:

#include "raylib.h"

int main() {
    InitWindow(800, 600, "Raylib Window");
    while (!WindowShouldClose()) {
        BeginDrawing();
        DrawCircle(400, 300, 100, GREEN);

Both libraries provide simple ways to create windows and draw shapes, but SFML uses a more object-oriented approach, while Raylib opts for a more procedural style. SFML's code is typically more verbose, while Raylib aims for conciseness and simplicity.

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

raylib is a simple and easy-to-use library to enjoy videogames programming.

raylib is highly inspired by Borland BGI graphics lib and by XNA framework and it's especially well suited for prototyping, tooling, graphical applications, embedded systems and education.

NOTE for ADVENTURERS: raylib is a programming library to enjoy videogames programming; no fancy interface, no visual helpers, no debug button... just coding in the most pure spartan-programmers way.

Ready to learn? Jump to code examples!



GitHub Releases Downloads GitHub Stars GitHub commits since tagged version GitHub Sponsors Packaging Status License

Discord Members Reddit Static Badge Youtube Subscribers Twitch Status

Windows Linux macOS WebAssembly

CMakeBuilds Windows Examples Linux Examples

features

  • NO external dependencies, all required libraries are bundled into raylib
  • Multiple platforms supported: Windows, Linux, MacOS, RPI, Android, HTML5... and more!
  • Written in plain C code (C99) using PascalCase/camelCase notation
  • Hardware accelerated with OpenGL (1.1, 2.1, 3.3, 4.3, ES 2.0, ES 3.0)
  • Unique OpenGL abstraction layer (usable as standalone module): rlgl
  • Multiple Fonts formats supported (TTF, OTF, Image fonts, AngelCode fonts)
  • Multiple texture formats supported, including compressed formats (DXT, ETC, ASTC)
  • Full 3D support, including 3D Shapes, Models, Billboards, Heightmaps and more!
  • Flexible Materials system, supporting classic maps and PBR maps
  • Animated 3D models supported (skeletal bones animation) (IQM, M3D, glTF)
  • Shaders support, including model shaders and postprocessing shaders
  • Powerful math module for Vector, Matrix and Quaternion operations: raymath
  • Audio loading and playing with streaming support (WAV, QOA, OGG, MP3, FLAC, XM, MOD)
  • VR stereo rendering support with configurable HMD device parameters
  • Huge examples collection with +140 code examples!
  • Bindings to +70 programming languages!
  • Free and open source

basic example

This is a basic raylib example, it creates a window and draws the text "Congrats! You created your first window!" in the middle of the screen. Check this example running live on web here.

#include "raylib.h"

int main(void)
{
    InitWindow(800, 450, "raylib [core] example - basic window");

    while (!WindowShouldClose())
    {
        BeginDrawing();
            ClearBackground(RAYWHITE);
            DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
        EndDrawing();
    }

    CloseWindow();

    return 0;
}

build and installation

raylib binary releases for Windows, Linux, macOS, Android and HTML5 are available at the Github Releases page.

raylib is also available via multiple package managers on multiple OS distributions.

Installing and building raylib on multiple platforms

raylib Wiki contains detailed instructions on building and usage on multiple platforms.

Note that the Wiki is open for edit, if you find some issues while building raylib for your target platform, feel free to edit the Wiki or open an issue related to it.

Setup raylib with multiple IDEs

raylib has been developed on Windows platform using Notepad++ and MinGW GCC compiler but it can be used with other IDEs on multiple platforms.

Projects directory contains several ready-to-use project templates to build raylib and code examples with multiple IDEs.

Note that there are lots of IDEs supported, some of the provided templates could require some review, so please, if you find some issue with a template or you think they could be improved, feel free to send a PR or open a related issue.

learning and docs

raylib is designed to be learned using the examples as the main reference. There is no standard API documentation but there is a cheatsheet containing all the functions available on the library a short description of each one of them, input parameters and result value names should be intuitive enough to understand how each function works.

Some additional documentation about raylib design can be found in raylib GitHub Wiki. Here are the relevant links:

contact and networks

raylib is present in several networks and raylib community is growing everyday. If you are using raylib and enjoying it, feel free to join us in any of these networks. The most active network is our Discord server! :)

contributors

license

raylib is licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows static linking with closed source software. Check LICENSE for further details.

raylib uses internally some libraries for window/graphics/inputs management and also to support different file formats loading, all those libraries are embedded with and are available in src/external directory. Check raylib dependencies LICENSES on raylib Wiki for details.