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

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 specially 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 auto-debugging... just coding in the most pure spartan-programmers way.

Ready to learn? Jump to code examples!


GitHub contributors GitHub All Releases GitHub commits since tagged version License

Chat on Discord GitHub stars Twitter Follow Subreddit subscribers

Windows Linux macOS Android WebAssembly CMakeBuilds

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) in PascalCase/camelCase notation
  • Hardware accelerated with OpenGL (1.1, 2.1, 3.3 or ES 2.0)
  • Unique OpenGL abstraction layer (usable as standalone module): rlgl
  • Multiple Fonts formats supported (TTF, XNA fonts, AngelCode fonts)
  • Outstanding texture formats support, 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)
  • Shaders support, including model and postprocessing shaders.
  • Powerful math module for Vector, Matrix and Quaternion operations: raymath
  • Audio loading and playing with streaming support (WAV, OGG, MP3, FLAC, XM, MOD)
  • VR stereo rendering support with configurable HMD device parameters
  • Huge examples collection with +120 code examples!
  • Bindings to +50 programming languages!
  • Free and open source.

raylib uses on its core module the outstanding GLFW3 library, embedded in the form of rglfw module, to avoid external dependencies.

raylib uses on its raudio module, the amazing miniaudio library to support multiple platforms and multiple audio backends.

raylib uses internally several single-file header-only libraries to support different fileformats loading and saving, all those libraries are embedded with raylib and available in src/external directory. Check raylib Wiki for a detailed list.

On Android platform, native_app_glue module (provided by Android NDK) and native Android libraries are used to manage window/context, inputs and activity life cycle.

On Raspberry Pi 0,1,2,3 platform (native mode), Videocore API and EGL libraries are used for window/context management. Inputs are processed using evdev Linux libraries

On Raspberry Pi 4 platform (native mode), DRM subsystem and GBM API libraries are used for window/context management. Inputs are processed using evdev Linux libraries

On Web platform, raylib uses emscripten provided libraries for several input events management, specially noticeable the touch events support.

build and installation

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

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

Installing and building raylib via vcpkg

You can download and install raylib using the vcpkg dependency manager:

  git clone https://github.com/Microsoft/vcpkg.git
  cd vcpkg
  ./bootstrap-vcpkg.sh
  ./vcpkg integrate install
  vcpkg install raylib

The raylib port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.

Installing and building raylib via conan

You can download and install raylib using the conan dependency manager:

  https://docs.conan.io/en/latest/getting_started.html

The raylib recipe in conan is kept up to date by conan team members and community contributors. If the version is out of date, please create an issue or pull request on the conan-center-index repository.

Building raylib on multiple platforms

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

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

Using 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, please, if you find some issue with some template or you think they could be improved, feel free to send a PR or open a related issue.

contact

If you are using raylib and enjoying it, please, join our Discord server and let us know! :)

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.

Owner
Ray
I make videogames and tools to make videogames. I teach videogames dev. Always available for talks, conferences and master classes.
Ray
Comments
  • [core] RPI4 without X11

    [core] RPI4 without X11

    In init device core.c #define RPI4 Initrpi4(); #else Normal init rpi 2 3 bla bla #endif

    ////////////////////// RPI4InitDevice.h // gcc -o drm-gbm drm-gbm-mod.c -ldrm -lgbm -lEGL -lGL -I/usr/include/libdrm

    //---------------------------------------------------------------------- //-------- Trying to get OpenGL ES screen on RPi4 without X //-------- based on drm-gbm https://github.com/eyelash/tutorials/blob/master/drm-gbm.c //-------- and kmscube https://github.com/robclark/kmscube //-------- [email protected] //----------------------------------------------------------------------

    #include <xf86drm.h> #include <xf86drmMode.h> #include <gbm.h> #include <EGL/egl.h> #include <GL/gl.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #include <stdio.h>

    #define EXIT(msg) { fputs (msg, stderr); exit (EXIT_FAILURE); }

    // global variables declarations

    static int device; static drmModeRes *resources; static drmModeConnector *connector; static uint32_t connector_id; static drmModeEncoder *encoder; static drmModeModeInfo mode_info; static drmModeCrtc *crtc; static struct gbm_device *gbm_device; static EGLDisplay display; static EGLContext context; static struct gbm_surface *gbm_surface; static EGLSurface egl_surface; EGLConfig config; EGLint num_config; EGLint count=0; EGLConfig *configs; int config_index; int i;

    static struct gbm_bo *previous_bo = NULL; static uint32_t previous_fb;

    static EGLint attributes[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 0, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE };

    static const EGLint context_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };

    struct gbm_bo *bo; uint32_t handle; uint32_t pitch; int32_t fb; uint64_t modifier;

    static drmModeConnector *find_connector (drmModeRes *resources) {

    for (i=0; icount_connectors; i++) { drmModeConnector *connector = drmModeGetConnector (device, resources->connectors[i]); if (connector->connection == DRM_MODE_CONNECTED) {return connector;} drmModeFreeConnector (connector); } return NULL; // if no connector found }

    static drmModeEncoder *find_encoder (drmModeRes *resources, drmModeConnector *connector) {

    if (connector->encoder_id) {return drmModeGetEncoder (device, connector->encoder_id);} return NULL; // if no encoder found }

    static void swap_buffers () {

    eglSwapBuffers (display, egl_surface); bo = gbm_surface_lock_front_buffer (gbm_surface); handle = gbm_bo_get_handle (bo).u32; pitch = gbm_bo_get_stride (bo); drmModeAddFB (device, mode_info.hdisplay, mode_info.vdisplay, 24, 32, pitch, handle, &fb); drmModeSetCrtc (device, crtc->crtc_id, fb, 0, 0, &connector_id, 1, &mode_info); if (previous_bo) { drmModeRmFB (device, previous_fb); gbm_surface_release_buffer (gbm_surface, previous_bo); } previous_bo = bo; previous_fb = fb; }

    static void draw (float progress) {

    glClearColor (1.0f-progress, progress, 0.0, 1.0); glClear (GL_COLOR_BUFFER_BIT); swap_buffers (); }

    static int match_config_to_visual(EGLDisplay egl_display, EGLint visual_id, EGLConfig *configs, int count) {

    EGLint id; for (i = 0; i < count; ++i) { if (!eglGetConfigAttrib(egl_display, configs[i], EGL_NATIVE_VISUAL_ID,&id)) continue; if (id == visual_id) return i; } return -1; }

    Bool initrpi4 () {

    device = open ("/dev/dri/card1", O_RDWR); resources = drmModeGetResources (device); connector = find_connector (resources); connector_id = connector->connector_id; mode_info = connector->modes[0]; encoder = find_encoder (resources, connector); crtc = drmModeGetCrtc (device, encoder->crtc_id); drmModeFreeEncoder (encoder); drmModeFreeConnector (connector); drmModeFreeResources (resources); gbm_device = gbm_create_device (device); gbm_surface = gbm_surface_create (gbm_device, mode_info.hdisplay, mode_info.vdisplay, GBM_FORMAT_XRGB8888, GBM_BO_USE_SCANOUT|GBM_BO_USE_RENDERING); display = eglGetDisplay (gbm_device); eglInitialize (display, NULL ,NULL); eglBindAPI (EGL_OPENGL_API); eglGetConfigs(display, NULL, 0, &count); configs = malloc(count * sizeof *configs); eglChooseConfig (display, attributes, configs, count, &num_config); config_index = match_config_to_visual(display,GBM_FORMAT_XRGB8888,configs,num_config); context = eglCreateContext (display, configs[config_index], EGL_NO_CONTEXT, context_attribs); egl_surface = eglCreateWindowSurface (display, configs[config_index], gbm_surface, NULL); free(configs); eglMakeCurrent (display, egl_surface, egl_surface, context);

    Return here...

    drmModeSetCrtc (device, crtc->crtc_id, crtc->buffer_id, crtc->x, crtc->y, &connector_id, 1, &crtc->mode); drmModeFreeCrtc (crtc); if (previous_bo) { drmModeRmFB (device, previous_fb); gbm_surface_release_buffer (gbm_surface, previous_bo); } eglDestroySurface (display, egl_surface); gbm_surface_destroy (gbm_surface); eglDestroyContext (display, context); eglTerminate (display); gbm_device_destroy (gbm_device);

    close (device); return 0; }

  • [build] Make raylib available in package managers

    [build] Make raylib available in package managers

    This would ease deployment quite a bit for users. The package should install a tagged release (e.g. 1.9.4-dev). If a more up-to-date or development snapshot can be requested, it should download the tarball for the newest master branch commit. See https://github.com/Homebrew/homebrew-core/commit/7f7b4bc0a604c8e6a9ccc117bde37245de61ff30 for an example.

    macOS

    Windows

    Linux

    • [X] openSUSE
    • [X] Arch User Repositories (AUR)
    • [x] Linuxbrew
    • [ ] Gentoo
    • [ ] Your Linux distro's package repositories

    BSD

    • [X] FreeBSD
    • [ ] Your BSD's ports tree?

    If you are able and willing to help, please tell.

  • [core] Mouse movements are bound to the screen resolution

    [core] Mouse movements are bound to the screen resolution

    Issue description

    On the maze example the mouse movements are bound to the screen resolution I have. Also the camera movements are shuttering when I hold move key.

    Environment

    Raspberry PI 4 no X11, 446f9ff commit. PLATFORM_DRM.

  • [build] Android APK building from command line

    [build] Android APK building from command line

    Just studying the possibility to directly build .apk programs from command line... to include with raylib all required tools, curated and packed in a single zip.

    A lot of tools are involved in APK generation and they come in different Android packages, more info here.

    Here it is a list with some of the command line tools provided: https://developer.android.com/studio/command-line/index.html

    Android APK building using ANT

    https://stuff.mit.edu/afs/sipb/project/android/docs/tools/building/building-cmdline.html

    Android APK building in raw mode (calling all required tools directly)

    1. Code compilation, standalone toolchain could be used
    2. Executable and assets packaging into .apk (unaligned, unsigned), using aapt program
    3. Use dx tool to convert Java bytecode to Dalvik bytecode if required
    4. Sign APK with a key using jarsigner tool, to generate key use keytool (info)
    5. Aligning and optimizing APK, using zipalign tool

    Note that .apk generation tools aapt and dx are included with Android build tools (installed with sdkmanager). Here some info on aapt usage: http://elinux.org/Android_aapt.

    A quite good guide on this process can be found here.

  • raylib 2.6 roadmap

    raylib 2.6 roadmap

    raylib has grown a lot in the last years and like in the past, I feel is time to sit down and think carefully about raylib next steps. It's very easy to lose focus and keep adding features to make raylib the next big engine... that's not raylib pourpose.

    So, for next raylib installment, I'll try to focus efforts on library stability and core features to improve the multiplatform raylib experience. I'll try to leave aside new 3d features... 3d requires lot of effort and time.

    Proposed improvements:

    • DONE [core] Frame stuttering when using Sleep() mechanisms. This issue worries me, when avoiding the BUSY_WAIT_LOOP, it seems there is a micro-second delay every second or so, it seems related to the time required to recover from the system halt. I investigated it but I couldn't find a solution yet. Help is welcome! #865 Possible solution: https://github.com/raysan5/raylib/commit/42d56d2f379f2160918c18e400ea657f5c1fd364

    • DONE [core] Input mechanisms review, try to unify it between platforms. Specially focus on:

      • SKIP Raspberry Pi input system, reviewed several times in the last year to replace raw keyboard input reading mechanism by evdev based input reading (inputs already processed by OS), both mechanisms are enabled at this moment for compatibility reasons (SSH keyboard support) but most probably only evdev one should be available. #863
      • DONE Android and HTML5 touch input system should be reviewed to properly scale inputs when framebuffer does not match display resolution and it's consequently scaled and offseted. #163
      • DONE Desktop and HTML5 inputs should be redesigned to support mouse and touch inputs as they were the same, so the same applications could work indistintly with mouse and touch. #726
    • DONE [core] Improve High DPI support. This is tricky, High DPI means that depending on the screen DPI your fixed pixel-size applications will look bigger or smaller on the screen. Solution implies re-scaling application framebuffer and mouse/touch inputs to match an equivalent resolution for the new DPI... it looks like a hack to me and doing that scaling brokes any pixel-perfect design of the original application, for example fonts. Additionally, every OS deals with that in a different way, some OS could automatically scale mouse input or even display window. I have to find a solution... #826, #837

    • DONE [rlgl] This module has already been redesigned several times to improve draw batching mechanism. It was lately reviewed to improve push/pop vertex transformations, similar to OpenGL 1.1. Right now, those stored transformations are not applied to mesh drawing, it shouldn't be difficult to support it: #901 #902

    • DONE [textures] Review ImageDraw() function. This is the base function for all Image drawing funtions (including text drawing on Image), that's the core for the basic 2d software renderer provided by raylib, it has some issues and it should be reviewed. #555

    • DONE [raudio] This module was redesigned some time ago to use the amazing miniaudio library but base design still comes from the previous OpenAL implementation, I would like to review and improve internal library structure and also promote its standalone usage mode. Some points to review:

      • DONE Review AudioBuffers vs AudioStream structures, maybe they can be unified and exposed to the user for custom audio streamming implementations.
      • DONE Review Music structure to avoid an opaque structure and expose Music parameters to the users, it will also make things easier for people creating bindings to raylib.
      • SKIP Support for WAV music streaming, same as any other audio format. Right now WAV files are fully loaded into memory.
    • DONE [examples] Some examples do not work on some platforms and require review, some new examples are also proposed:

      • DONE Review examples based on shaders on HTML5/RPI. #847
      • DONE Review examples based on shaders on RPI. #851
      • DONE Some new examples proposed: #890
      • SKIP Examples using Camera on Android
    • SKIP [rlvk] It's been long time I want to dig into Vulkan backend but the truth is that I can't find the benefits for raylib. In any case, I don't discard jumping into it if I had enough time.

    Well, this is the intended roadmap for next raylib. Nothing set on stone!

    Please, let me know your thoughts! :)

  • [rnet] Simple and easy-to-use network module for raylib

    [rnet] Simple and easy-to-use network module for raylib

    As already mentioned several times by raylib community, a network module is a missing piece on raylib. Long ago I started drafting a possible network module API for raylib but due to lack of resources, project was stopped... I start this issue to list project specifications and references.

    rnet is a simple and easy-to-use network library. Some desired features:

    • Available as raylib module (rnet.c) but also usable as a standalone library
    • No external dependencies (only the standard system libraries - winsock2.h/socket.h)
    • Self-contained in a single file (header-only) or two portable files: rnet.h + rnet.c
    • Focused on UDP protocol (probably the most useful for games)
    • Support WEB (WebSockets) and ANDROID platforms (if possible)

    Just as a quick reference, the following APIs have been analyzed:

    I'm not an expert on network programming, actually last time I remember doing some sockets code was on University... but here it is basic raynet API proposal (probably very improvable):

    void InitNetworkDevice(NetworkConfig config);
    void CloseNetworkDevice();
    int NetworkConnect(int hostId, const char *address, int port);
    void NetworkDisconnect(int hostId, int connectionId);
    void NetworkSend(int hostId, int connectionId, int channelId, void *data, int length);
    int NetworkReceive(int hostId, int connectionId, int channelId, void *data, int length);
    // Maybe hostId, connectionId and channelId can be a `struct NetworkSocket`.
    

    Just keep in mind this API is a very rough proposal...

    EDIT: Added to list desired support for WEB and ANDROID.

  • Licensing question

    Licensing question

    My submission of raylib 3.0.0 to openSUSE has been declined. The bot sais:

    Contains non-commercial licenses.
    Diff to closest match 153843:
    Found new license CC-BY-NC-3.0 (risk 4) not present in old report
    Found new license SCEA (risk 3) not present in old report
    

    So raylib now ships things with SCEA and CC-BY-NC-3.0 license? That's correct? Then I'll add them to the spec file.

  • raylib 2.0 release planning

    raylib 2.0 release planning

    I'm just listing in this issue the latest planned features that remain to be added for the official release of raylib 2.0.

    In the last 6-7 months raylib has really changed a lot and some long-term objectives for the project have been accomplished, specially remarkable the complete removal of external library dependencies, currently all required dependencies are seamlessly build with raylib library (and included with raylib sources).

    Current list of changes included in this future release could be found in CHANGELOG.

    This is the list of remaining points I'd like to accomplish (a part of taking care of some random bug):

    • [x] LoadFont() - improve font packaging on atlas #375
    • [x] LoadFontSDF() - support signed distance field font atlas generation #376
    • [ ] TCC compiler setup as default to be included with Windows Installer #435
    • [x] Prepare Notepad++ scripts for TCC compiling (source and examples)
    • [x] Review Notepad++ intellisense for new raylib functions (XML)
    • [x] Review raylib examples -> some could be broken...
    • [x] Replace the dwarf model and textures for something more aligned with raylib style (low-poly?)
    • [x] Complete review of Wiki for different platforms compile/usage.

    Those are the my main concerns, feel free to comment if some important point is missing.

  • [build] Support Tiny C compiler

    [build] Support Tiny C compiler

    This improvement has a double pourpose, first just offer an alternative to the already supported C compilers (GCC, clang, MSVC), second, offer a really tiny lightweight environment to play with raylib.

    raylib is provided to students as an installer including the library, a preconfigured version of Notepad++ and MinGW package. This installer is pretty big and I'd like to reduce its size. Current MinGW package is around 200 MB; in comparison, TCC with basic libraries is just around 3 MB.

  • [audio] Chiptunes support

    [audio] Chiptunes support

    Wondering if there was any support for this. I have been looking into it and am going this route: https://github.com/kd7tck/raylib/commit/8a16d76a6554bbf06969dc9d6bbae715c6f36a75

    Wanted a little feedback, wondering if better libraries are out there.

  • [build] Make raylib available in package managers

    [build] Make raylib available in package managers

  • [models] Batching not working for DrawBillboard with >8190 billboards

    [models] Batching not working for DrawBillboard with >8190 billboards

    • [x] I tested it on latest raylib version from master branch
    • [x] I checked there is no similar issue already reported
    • [x] My code has no errors or misuse of raylib

    Issue description

    The example code below is a slightly modified version of the official models-billboard.c example that draws many billboards. Up to a number of 8190 billboards -- suspiciously close to 8192 which is the default for RL_DEFAULT_BATCH_BUFFER_ELEMENTS -- this produces the expected output (see image below), but beginning with 8191 billboards, the screen remains empty.

    Environment

    Windows 10, official Raylib+MingW, version 4.0 release, HEAD 4.2-dev binary was compiled with:

    gcc models_billboard2.c -lraylib -lgdi32 -luser32 -lshell32 -lwinmm -o models_billboard2.exe

    Code Example (models_billboard2.c)

    This is a slightly modified version of the official models-billboard.c example:

    /*******************************************************************************************
    *
    *   Modified raylib [models] example - Drawing large numbers of billboards at random positions
    *
    *   This example has been created using raylib 1.3 (www.raylib.com)
    *   raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
    *
    *   Copyright (c) 2015 Ramon Santamaria (@raysan5)
    *
    ********************************************************************************************/
    #include <stddef.h>
    #include <stdlib.h>
    #include "raylib.h"
    
    #define bb_num 8191 // 8190 works
    Vector3 bbpos[bb_num];
    
    int main(void)
    {
        // Initialization
        //--------------------------------------------------------------------------------------
        const int screenWidth = 800;
        const int screenHeight = 450;
    
        InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards");
    
        // Define the camera to look into our 3d world
        Camera camera = { 0 };
        camera.position = (Vector3){ 5.0f, 4.0f, 5.0f };
        camera.target = (Vector3){ 0.0f, 2.0f, 0.0f };
        camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
        camera.fovy = 45.0f;
    
        Texture2D bill = LoadTexture("resources/billboard.png");     // Our texture billboard
    
        // setup random bill board positions    
        for (int i = 0; i < bb_num; i++)
        {
            bbpos[i] = (Vector3){100.0*((float)rand()/RAND_MAX) - 50.0, 100.0*((float)rand()/RAND_MAX) - 50.0, 100.0*((float)rand()/RAND_MAX) - 50.0};
        }
    
        SetCameraMode(camera, CAMERA_ORBITAL);  // Set an orbital camera mode
        SetTargetFPS(60);                       // Set our game to run at 60 frames-per-second
        //--------------------------------------------------------------------------------------
    
        // Main game loop
        while (!WindowShouldClose())            // Detect window close button or ESC key
        {
            // Update
            //----------------------------------------------------------------------------------
            UpdateCamera(&camera);              // Update camera
            //----------------------------------------------------------------------------------
            // Draw
            //----------------------------------------------------------------------------------
            BeginDrawing();
    
                ClearBackground(RAYWHITE);
            
                BeginMode3D(camera);
            
                    //DrawGrid(10, 1.0f);        // Draw a grid
                    for (int i = 0; i < bb_num; i++) 
                    {
                        DrawBillboard(camera, bill, bbpos[i], 1.0f, WHITE);
                    }
    
                EndMode3D();
            
                DrawFPS(10, 10);
            
            EndDrawing();
            //----------------------------------------------------------------------------------
        }
    
        // De-Initialization
        //--------------------------------------------------------------------------------------
        UnloadTexture(bill);        // Unload texture
    
        CloseWindow();              // Close window and OpenGL context
        //--------------------------------------------------------------------------------------
    
        return 0;
    }
    

    Note: this needs to be run in the same folder as examples/models/models_billboard.c to pick-up the resources folder

    Screenshots

    8190 billboards

    8191 billboards

  • [rtexture] ColorAlphaBlend round off error

    [rtexture] ColorAlphaBlend round off error

    Please, before submitting a new issue verify and check:

    • [yes] I tested it on latest raylib version from master branch
    • [yes] I checked there is no similar issue already reported
    • [maybe] My code has no errors or misuse of raylib

    Issue description

    In ColorAlphaBlend, source corlor is tinted before blend as the following:

    Color ColorAlphaBlend(Color dst, Color src, Color tint)
    {
        Color out = WHITE;
    
        // Apply color tint to source color
        src.r = (unsigned char)(((unsigned int)src.r*(unsigned int)tint.r) >> 8);
        src.g = (unsigned char)(((unsigned int)src.g*(unsigned int)tint.g) >> 8);
        src.b = (unsigned char)(((unsigned int)src.b*(unsigned int)tint.b) >> 8);
        src.a = (unsigned char)(((unsigned int)src.a*(unsigned int)tint.a) >> 8);
    

    There's a round off error in these calculations. Since we usally define color's rgba components in range 0-255, src.r*tint.r >> 8 will always generate a new number that is less than the original number.

    So even if we set the tint color as WHITE, the result is still not the original source color. If we alphablend a color many times, finally it will become BLACK.

    Code Example

    I'm writing a program that display the sin wave animatedly. I'm trying to copy part of the last frame in each iteration, to make the wave line. It's done by the ImageDraw funtion, and it calls ColorAlphaBlend. The frame becomes blacked as it is copied many times.

    #include <raylib.h>
    #include <math.h>
    
    
    
    int main() {
    	InitWindow(1200,480,"rdrawing");
    	SetTraceLogLevel(LOG_WARNING);
    	SetTargetFPS(60);
    	
    	Image imgUnitCircle=GenImageColor(400,480,BLANK);
    	
    	Image imgSin=GenImageColor(760,480,BLANK);
    	
    	float r = 0;
    	float lastY=240;
    	float x,y;
    	while(!WindowShouldClose()) {
    		//update datas
    		r += 0.02;
    		if (r > PI * 2) r -= PI * 2;
    		x=200+150*cos(r);
    		y=240-150*sin(r);
    		//update image (in CPU)
    		ImageClearBackground(&imgUnitCircle,BLANK);
    		ImageDrawCircle(&imgUnitCircle,200,240,150,RED);
    		ImageDrawLine(&imgUnitCircle,200,240,x,y,RED);
    		ImageDrawCircle(&imgUnitCircle,x,y,7,DARKBROWN);
    		Texture textureUnitCircle = LoadTextureFromImage(imgUnitCircle);
    		
    		Image imgTemp=ImageCopy(imgSin);
    		ImageClearBackground(&imgSin,WHITE);
    		ImageDraw(&imgSin,imgTemp,
    			(Rectangle){0,0,imgTemp.width-1,imgTemp.height},
    			(Rectangle){1,0,imgTemp.width-1,imgTemp.height},WHITE);
    		UnloadImage(imgTemp);
    		ImageDrawLine(&imgSin,0,y,1,lastY,RED);
    		Texture textureSin = LoadTextureFromImage(imgSin);
    		lastY=y;
    		
    		//Drawing in GPU
    		BeginDrawing();
    		ClearBackground(WHITE);
    		DrawTexture(textureUnitCircle,0,0,WHITE);
    		DrawTexture(textureSin,400,0,WHITE);
    		EndDrawing();
    		UnloadTexture(textureSin);
    		UnloadTexture(textureUnitCircle);
    	}	
    	//Clean up
    	UnloadImage(imgSin);
    	UnloadImage(imgUnitCircle);
    	CloseWindow();
    }
    
    
  • [models] Instanced Drawing with Custom Shader Corrupts Drawing with Default Shader

    [models] Instanced Drawing with Custom Shader Corrupts Drawing with Default Shader

    • [x] I tested it on latest raylib version from master branch
    • [x] I checked there is no similar issue already reported (#2211 is related but isn't the same sort of issue).
    • [x] My code has no errors or misuse of raylib

    Issue description

    In my original project, I was trying to draw instanced copies of a particular mesh, and then use that same mesh to draw a non-instanced version of it with the default material. However, something about the DrawMeshInstanced(...) call seemed to corrupt the state of the renderer and made the non-instanced version not draw correctly.

    This only occurs when the vertex shader of the instanced material does not declare the attributes for vertex normal and color, which can be demonstrated by replacing the example's shader with "based_lighting_instanced.vs" from the raylib examples.

    Although this can be seen as a misconfiguration on the user's end, this error does not occur when instancing is not involved. Even so, an error in the instanced vertex shader should not affect rendering using the default shader as well.

    Environment

    Linux, Pop! OS (Ubuntu & Gnome desktop), OpenGL 4.6.0 NVIDIA 510.73.05, NVIDIA GeForce GTX 1650, NVIDIA proprietary driver version 510.73.05

    Issue Screenshot

    Result of the code example below: image Result of the code example, with the DrawMeshInstanced(...) line removed. image Expected result (Achieved by replacing "base_instanced_stripped.vs" with "base_lighting_instanced.vs") image

    Code Example

    #include "raylib.h"
    #include "raymath.h"
    
    #include <stdlib.h>
    #include <math.h>
    
    #define MAX_INSTANCES  10
    
    int main(void)
    {
        const int screenWidth = 800;
        const int screenHeight = 450;
    
        InitWindow(screenWidth, screenHeight, "raylib [shaders] example - mesh instancing");
        SetTargetFPS(60);
    
        Camera camera = { 0 };
        camera.position = (Vector3){ -25.0f, 25.0f, -25.0f };
        camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
        camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
        camera.fovy = 45.0f;
        camera.projection = CAMERA_PERSPECTIVE;
        SetCameraMode(camera, CAMERA_ORBITAL);
    
        Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
    
        Matrix *transforms = RL_MALLOC(MAX_INSTANCES*sizeof(Matrix));
    
        for (int i = 0; i < MAX_INSTANCES; i++) {
            transforms[i] = MatrixTranslate(0.0f, -10.0f, 0.0f);
        }
    
        //Load a shader that's missing attributes for vertex color and normals.
        Shader shader = LoadShader("resources/shaders/glsl330/base_instanced_stripped.vs",
                                   "resources/shaders/glsl330/base.fs");
    
        shader.locs[SHADER_LOC_MATRIX_MVP] = GetShaderLocation(shader, "mvp");
        shader.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocationAttrib(shader, "instanceTransform");
        
        //Instanced material
        Material instancedMaterial = LoadMaterialDefault();
        instancedMaterial.shader = shader;
        instancedMaterial.maps[MATERIAL_MAP_DIFFUSE].color = RED;
        
        //Non instanced material
        Material normalMaterial = LoadMaterialDefault();
        normalMaterial.maps[MATERIAL_MAP_DIFFUSE].color = BLUE;
    
        while (!WindowShouldClose())
        {
            UpdateCamera(&camera);
            
            BeginDrawing();
    
                ClearBackground(RAYWHITE);
    
                BeginMode3D(camera);
                	//The cubes drawn before and after the instanced draw call are not rendered unless the instanced draw call is removed.
                    DrawMesh(cube, normalMaterial, MatrixTranslate(-2.0f, 0.0f, 0.0f));
                    
                    DrawMeshInstanced(cube, instancedMaterial, transforms, MAX_INSTANCES);
                    
                    DrawMesh(cube, normalMaterial, MatrixTranslate(2.0f, 0.0f, 0.0f));
                EndMode3D();
    
            EndDrawing();
        }
    	
        RL_FREE(transforms);
    
        CloseWindow(); 
    
        return 0;
    }
    

    Shader code for "base_instanced_stripped.vs":

    #version 330
    
    in vec3 vertexPosition;
    in vec2 vertexTexCoord;
    
    in mat4 instanceTransform;
    
    uniform mat4 mvp;
    uniform mat4 matNormal;
    
    out vec3 fragPosition;
    out vec2 fragTexCoord;
    
    void main()
    {
        mat4 mvpi = mvp*instanceTransform;
    
        fragPosition = vec3(mvpi*vec4(vertexPosition, 1.0));
        fragTexCoord = vertexTexCoord;
    
        gl_Position = mvpi*vec4(vertexPosition, 1.0);
    }
    

    Other shaders mentioned are from the raylib examples repository.

  • [audio] Distortion/echo produced when multiple sounds are loaded

    [audio] Distortion/echo produced when multiple sounds are loaded

    • [x] I tested it on latest raylib version from master branch
    • [x] I checked there is no similar issue already reported
    • [x] My code has no errors or misuse of raylib

    Issue description

    Playing a short wave form leads to a distorted, time-delayed, very high-pitch "echo" of the sound being played after the sound. This happens when another (or more?) sound samples happen to also have been loaded by LoadSound. If the problematic sound is the only one that is being loaded by LoadSound, the echo/distortion does not occur and the sound is played fine.

    The example code below is a very slightly modified version of the official Multichannel sound playing example. When it is run and [ENTER] is pressed to play the fxWav2 sound, it produces the high-pitched echo a short time after the actual sound has finished. If however fxWav2 is the only sound that is being loaded by LoadSound, i.e. if the lines for fxWav are commented out, the fxWav2 produces no such echo, i.e. the sound plays fine!

    Environment

    Windows 10, official Raylib+MingW, version 4.0 release binary was compiled with:

    gcc raytest.c -lraylib -lgdi32 -luser32 -lshell32 -lwinmm -o raytest.exe

    EDIT: Bug also exists in HEAD 4.2-dev

    Code Example (raytest.c)

    This is a marginally modified version of the official Multichannel sound playing example:

    /*******************************************************************************************
    *
    *   raylib [audio] example - Multichannel sound playing
    *
    *   This example has been created using raylib 2.6 (www.raylib.com)
    *   raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
    *
    *   Example contributed by Chris Camacho (@chriscamacho) and reviewed by Ramon Santamaria (@raysan5)
    *
    *   Copyright (c) 2019 Chris Camacho (@chriscamacho) and Ramon Santamaria (@raysan5)
    *
    ********************************************************************************************/
    
    #include "raylib.h"
    
    int main(void)
    {
        // Initialization
        //--------------------------------------------------------------------------------------
        const int screenWidth = 800;
        const int screenHeight = 450;
    
        InitWindow(screenWidth, screenHeight, "raylib [audio] example - Multichannel sound playing");
    
        InitAudioDevice();      // Initialize audio device
    
        Sound fxWav = LoadSound("resources/328715__robinhood76__06098-short-jump-swoosh.wav");         // Load WAV audio file
        Sound fxWav2 = LoadSound("resources/273578__n-audioman__flame04.wav");        // Load OGG audio file
    
        SetSoundVolume(fxWav, 0.2f);
    
        SetTargetFPS(60);       // Set our game to run at 60 frames-per-second
        //--------------------------------------------------------------------------------------
    
        // Main game loop
        while (!WindowShouldClose())    // Detect window close button or ESC key
        {
            // Update
            //----------------------------------------------------------------------------------
            if (IsKeyPressed(KEY_SPACE)) PlaySoundMulti(fxWav);     // Play a new ogg sound instance
            if (IsKeyPressed(KEY_ENTER)) PlaySoundMulti(fxWav2);     // Play a new wav sound instance
            //----------------------------------------------------------------------------------
    
            // Draw
            //----------------------------------------------------------------------------------
            BeginDrawing();
    
                ClearBackground(RAYWHITE);
    
                DrawText("MULTICHANNEL SOUND PLAYING", 20, 20, 20, GRAY);
                DrawText("Press SPACE to play new wav instance!", 200, 120, 20, LIGHTGRAY);
                DrawText("Press ENTER to play new wav2 instance!", 200, 180, 20, LIGHTGRAY);
    
                DrawText(TextFormat("CONCURRENT SOUNDS PLAYING: %02i", GetSoundsPlaying()), 220, 280, 20, RED);
    
            EndDrawing();
            //----------------------------------------------------------------------------------
        }
    
        // De-Initialization
        //--------------------------------------------------------------------------------------
        StopSoundMulti();       // We must stop the buffer pool before unloading
    
        UnloadSound(fxWav);     // Unload sound data
        UnloadSound(fxWav2);     // Unload sound data
    
        CloseAudioDevice();     // Close audio device
    
        CloseWindow();          // Close window and OpenGL context
        //--------------------------------------------------------------------------------------
    
        return 0;
    }
    

    The two wave forms are un-edited downloads of:

    "328715__robinhood76__06098-short-jump-swoosh.wav", https://freesound.org/people/Robinhood76/sounds/328715/

    "273578__n-audioman__flame04.wav", https://freesound.org/people/n_audioman/sounds/273578/

  • [core] `SetMousePosition()` delayed by one frame on X11 systems

    [core] `SetMousePosition()` delayed by one frame on X11 systems

    Please, before submitting a new issue verify and check:

    • [x] I tested it on latest raylib version from master branch
    • [x] I checked there is no similar issue already reported
    • [x] My code has no errors or misuse of raylib

    Issue description

    Copied from my Discord message - HK#2413

    I'm having an issue where calls to SetMousePosition are effectively delayed by 1 frame and I have no idea why. I'm in the process of writing my own first-person mouse look function but every time I try to reset the cursor to the middle of the screen, GetMousePosition reports the old position for an extra frame.

    Environment

    Arch Linux (X11 + dwm), OpenGL 4.6, AMD Radeon RX 580 Bug reproduced consistently

    Windows 10 virtual machine, OpenGL 4.6, Nvidia GTX 960 Could not reproduce bug

    Code Example

    #include "raylib.h"
    
    int main() {
        InitWindow(800, 600, "Mouse issue demo");
        SetTargetFPS(60);
    
        while (!WindowShouldClose()) {
            // If the mouse x position is > 100, reset it back to 5
            Vector2 mouse = GetMousePosition();
            TraceLog(LOG_INFO, "Mouse x: %f", mouse.x);
            if (mouse.x > 100) {
                TraceLog(LOG_INFO, "Mouse is > 100, resetting");
                SetMousePosition(5, mouse.y);
            }
    
            BeginDrawing();
                ClearBackground(BLACK);
                DrawLine(mouse.x, 0, mouse.x, 600, GREEN);
                DrawLine(100, 0, 100, 600, RED);
            EndDrawing();
        }
    
        CloseWindow();
    }
    

    If you move the mouse right at a medium speed, you can see the issue in the debug messages

    INFO: Mouse x: 92.000000
    INFO: Mouse x: 99.000000
    INFO: Mouse x: 106.000000
    INFO: Mouse is > 100, resetting                <- SetMousePosition called here
    INFO: Mouse x: 115.000000                      <- Next frame, mouse hasn't moved
    INFO: Mouse is > 100, resetting
    INFO: Mouse x: 13.000000
    INFO: Mouse x: 12.000000
    INFO: Mouse x: 19.000000
    
  • [core] Issues running in native mode with `PLATFORM_DRM` in Bullseye in RPI Zero W

    [core] Issues running in native mode with `PLATFORM_DRM` in Bullseye in RPI Zero W

    I'm trying to run raylib in native mode in RPI Zero W with latest RPI OS Bullseye and KMS driver. After installing required libraries (libgles2-dev, libgbm-dev, libdrm-dev), compilation works ok but program crashes on run:

    [email protected]:~/raylib/examples $ ./core/core_basic_window
    INFO: Initializing raylib 4.1-dev
    INFO: Supported raylib modules:
    INFO:     > rcore:..... loaded (mandatory)
    INFO:     > rlgl:...... loaded (mandatory)
    INFO:     > rshapes:... loaded (optional)
    INFO:     > rtextures:. loaded (optional)
    INFO:     > rtext:..... loaded (optional)
    INFO:     > rmodels:... loaded (optional)
    INFO:     > raudio:.... loaded (optional)
    INFO: DISPLAY: No graphic card set, trying platform-gpu-card
    INFO: DISPLAY: Failed to open platform-gpu-card, trying card1
    INFO: DISPLAY: Failed to open graphic card1, trying card0
    INFO: DISPLAY: Selected DRM connector mode 1280x720 ([email protected])
    INFO: DISPLAY: Device initialized successfully
    INFO:     > Display size: 1280 x 720
    INFO:     > Screen size:  1280 x 720
    INFO:     > Render size:  1280 x 720
    INFO:     > Viewport offsets: 0, 0
    INFO: GL: Supported extensions count: 52
    INFO: GL: OpenGL device information:
    INFO:     > Vendor:   Broadcom
    INFO:     > Renderer: VC4 V3D 2.1
    INFO:     > Version:  OpenGL ES 2.0 Mesa 20.3.5
    INFO:     > GLSL:     OpenGL ES GLSL ES 1.0.16
    INFO: GL: VAO extension detected, VAO functions loaded successfully
    INFO: GL: NPOT textures extension detected, full NPOT textures supported
    INFO: GL: ETC1 compressed textures supported
    INFO: TEXTURE: [ID 1] Texture loaded successfully (1x1 | R8G8B8A8 | 1 mipmaps)
    INFO: TEXTURE: [ID 1] Default texture loaded successfully
    INFO: SHADER: [ID 1] Vertex shader compiled successfully
    INFO: SHADER: [ID 2] Fragment shader compiled successfully
    INFO: SHADER: [ID 3] Program shader loaded successfully
    INFO: SHADER: [ID 3] Default shader loaded successfully
    INFO: RLGL: Render batch vertex buffers loaded successfully in RAM (CPU)
    INFO: RLGL: Render batch vertex buffers loaded successfully in VRAM (GPU)
    INFO: RLGL: Default OpenGL state initialized successfully
    INFO: TEXTURE: [ID 2] Texture loaded successfully (128x128 | GRAY_ALPHA | 1 mipmaps)
    INFO: FONT: Default font loaded successfully (224 glyphs)
    INFO: RPI: Opening input device: /dev/input/event1 (mouse )
    INFO: RPI: Opening keyboard device: /dev/input/event0
    WARNING: RPI: Failed to open Gamepad device, no gamepad available
    INFO: TIMER: Target time per frame: 16.667 milliseconds
    ERROR: DISPLAY: Failed GBM to lock front buffer
    Segmentation fault
    [email protected]:~/raylib/examples $
    

    The system is properly configured to run on native mode with Full KMS acceleration enabled:

    sudo raspi-config > Advance Options > A2 GL Driver > G2 GL (Full KMS) OpenGL desktop driver with full KMS
    

    Driver is properly enabled in /boot/config.txt

    # Enable DRM VC4 V3D driver
    dtoverlay=vc4-kms-v3d
    max_framebuffers = 2
    gpu_mem = 256
    

    In case it is relevant, user permissions have been reviewed:

    sudo usermod -a -G render pi
    

    The output is the HDMI, it should be the default output and it seems to be detected correctly:

    INFO: DISPLAY: No graphic card set, trying platform-gpu-card
    INFO: DISPLAY: Failed to open platform-gpu-card, trying card1
    INFO: DISPLAY: Failed to open graphic card1, trying card0
    INFO: DISPLAY: Selected DRM connector mode 1280x720 ([email protected])
    INFO: DISPLAY: Device initialized successfully
    

    The error is related to function gbm_surface_lock_front_buffer() -> ERROR: DISPLAY: Failed GBM to lock front buffer.

    Any idea?

    EDIT: useful info: https://symbolibre.org/graphics-acceleration-on-the-raspberry-pi-zero.html

Dragon's Dice Roller aims to be a lightweight, simple, reliable and easy-to-use dice roller for RPG games.

Dragon's Dice Roller is the first and (so far the only) open source RPG dice roller written in C available on GitHub. It aims to be a lightweight, simple, reliable and easy-to-use dice roller for any kind of role-playing game.

Apr 22, 2022
GB Studio is a quick and easy to use retro adventure game creator for Game Boy available for Mac, Linux and Windows
GB Studio is a quick and easy to use retro adventure game creator for Game Boy available for Mac, Linux and Windows

GB Studio is a quick and easy to use retro adventure game creator for Game Boy available for Mac, Linux and Windows

Jun 21, 2022
SKR_Physics is a lightweight and easy to use 2D physics engine which is written in C++.

SKR_Physics SKR_Physics is a lightweight and easy to use 2D physics engine which is written in C++. Features Rectangle based collision system Very sim

Mar 8, 2022
Ground Engine is an easy to use Game Engine for 3D Game Development written in C++
Ground Engine is an easy to use Game Engine for 3D Game Development written in C++

Ground Engine is an easy to use Game Engine Framework for 3D Game Development written in C++. It's currently under development and its creation will b

Jun 10, 2022
Simple, fast, easy to get started mid-level game engine written in Zig

Alka Game engine written in zig, compatible with master branch. This engine does provide a toolset for you but generally you have to implement how the

Apr 17, 2022
Simple Directmedia Layer, 1.2 branch ... ***DEPRECATED***, please use https://github.com/libsdl-org/SDL for new projects!

DEPRECATED The 1.2 branch of SDL is deprecated. While we occasionally collect fixes in revision control, there has not been a formal release since 201

Jun 2, 2022
Minetest is an open source voxel game engine with easy modding and game creation

Minetest is an open source voxel game engine with easy modding and game creation

Jun 22, 2022
Pure C math library for 2D and 3D programming

MATHC MATHC is a simple math library for 2D and 3D programming. Features Vectors (2D, 3D and 4D) (integer type and floating-point type) Quaternions Ma

Jun 23, 2022
dos-like is a programming library/framework, kind of like a tiny game engin
dos-like is a programming library/framework, kind of like a tiny game engin

dos-like is a programming library/framework, kind of like a tiny game engine, for writing games and programs with a similar feel to MS-DOS productions from the early 90s. But rather than writing code that would run on a real DOS machine, dos-like is about making programs which runs on modern platforms like Windows, Mac and Linux, but which attempts to recreate the look, feel, and sound of old DOS programs.

Jun 21, 2022
A set of libraries and tools to make MSX games using the C programming language.

ubox MSX lib This is a set of libraries and tools to make MSX games using the C programming language. There are three main components: ubox: thin wrap

May 30, 2022
DOSBox Pure is a new fork of DOSBox built for RetroArch/Libretro aiming for simplicity and ease of use.
DOSBox Pure is a new fork of DOSBox built for RetroArch/Libretro aiming for simplicity and ease of use.

DOSBox Pure is a fork of DOSBox, an emulator for DOS games, built for RetroArch/Libretro aiming for simplicity and ease of use.

Jun 16, 2022
bsnes is a Super Nintendo (SNES) emulator focused on performance, features, and ease of use.
bsnes is a Super Nintendo (SNES) emulator focused on performance, features, and ease of use.

bsnes is a Super Nintendo (SNES) emulator focused on performance, features, and ease of use.

Jun 15, 2022
A clone of the classic QBasic Gorillas written in the Zig programming language
A clone of the classic QBasic Gorillas written in the Zig programming language

⚡ Zig Gorillas ?? A clone of the classic QBasic Gorillas written in the Zig programming language. Take turns in throwing an exploding banana at each o

Jun 18, 2022
An OpenGL Engine Written In C Using A Very OOP-Like Way Of Programming

A Simple Engine in its very first stages of becoming a, Game Engine or just a framework for making games using OpenGL. Here are the features of the Op

May 27, 2022
A programming game, in which your goal is to help a group of dwarves establish a small outpost in the middle of a dangerous forest.
A programming game, in which your goal is to help a group of dwarves establish a small outpost in the middle of a dangerous forest.

"Since they were to come in the days of the power of Melkor, Aulë made the dwarves strong to endure. Therefore they are stone-hard, stubborn, fast in

Jan 8, 2022
Recreation of the MineStorm game for a student programming project.
Recreation of the MineStorm game for a student programming project.

MineStorm General information This project is a student project done for ISART Digital by Rémi SERRA and Alexandre PERCHÉ. The goal was to recreate th

Nov 14, 2021
Engine being created for homeworks in UPC Master's Degree in Advanced Programming for AAA Video Games.
Engine being created for homeworks in UPC Master's Degree in Advanced Programming for AAA Video Games.

Strawhat Engine Strawhat Engine is a game engine under construction that has model loading and camera movement features along with an editor. Reposito

May 18, 2022
A minecraft clone built in c++ opengl for the purpose of prefecting graphics programming skills.

LearnOpenGL - CLion This is a project template for OpenGL development with JetBrains CLion IDE. It was created mainly for LearnOpenGL tutorials. Inclu

Dec 28, 2021
This is the source repo for the book Game Programming Patterns

Note: Now that the book is done, I'm not actively working on it. There are only so many hours in the day, and I have other projects that need my love,

Jun 16, 2022