r/raylib

▲ 17 r/raylib

Recently started learning C with raylib cuz why not

Yea u read the title ik that and also raylib with C is fun as fuck like actually i recommend it

reddit.com
u/No_Fun_9896 — 9 hours ago
▲ 122 r/raylib+1 crossposts

Name: Conflict 3049 Type: Classic (Last Stand Scenario) Link: https://matty77.itch.io/conflict-3049

Greetings,

It's been a while but I spent some time recently doing a graphical update to my RTS Last Stand Scenario "Conflict 3049".

The vegetation has been changed as has the environmental graphics.

The shaders have been updated.

The explosions have been tweaked.

The game is available on itch io for a low price at the following link: https://matty77.itch.io/conflict-3049

Enjoy!

from Matt

u/Haunting_Art_6081 — 22 hours ago
▲ 6 r/raylib

How to detect Caps Lock/Scroll Lock/Num Lock state?

Is there a way to detect whether the lock functions are currently enabled or not? Based on this issue it seemed like the intention was for the key to be considered down while the lock was enabled and up while it's not, but it doesn't seem to function that way anymore. Checking the state of any of the lock keys just reflects the physical state of the key itself.

ChatGPT suggests the only solution is to write platform-specific implementations that use native APIs to check this. I can do that if I need to, but was surprised there wasn't something built in so wanted to check before I add that kind of complexity to my codebase.

u/Drakmyth — 15 hours ago
▲ 2 r/raylib

What's better language to work with raylib? Python vs C++

I have some python experience and it would be definietly easier for me, my C++ experience is limited, but it's not 0. Is there any major reason to work with C++ rather than with python? I'd also prefer python since setting things up is easier for me, personally I really hate setting up libraries in C++.

reddit.com
u/Azazo8 — 1 day ago
▲ 2 r/raylib+1 crossposts

Struggling to clear the framebuffer

Im writing a software renderer in C++ using glm and raylib, and i recently tried to draw a spinning triangle. The problem is that when i launched it the triangle leaves a trail of previously drawn triangles.

https://preview.redd.it/5plfv6kkhbbh1.png?width=804&format=png&auto=webp&s=6d1a6479e6b6c142f7c58572afd62bc904557ba8

I tried to fix it by rasterizing to a framebuffer and then drawing that framebuffer instead of drawing the pixels directly and using ClearBackground to refresh the screen, but doing it that way has still the same problem. ¿Why im having this problem even though im clearing the framebuffer?

EDIT: Now im using textures to draw the pixels to the screen instead of drawing them using DrawRectangle, but it still doesnt work.

This is the code for the rasterizer (sorry for sharing it like this, i havent uploaded this to github yet):

https://pastebin.com/Ns2LiSXv

The header file:

https://pastebin.com/xf5JhqFR

reddit.com
u/Otherwise-Pear2054 — 1 day ago
▲ 19 r/raylib

Made My First Raylib Snake Game !!

Am interested in low-level game dev and cpp, so I went through the raylib docs and made this. Its not that great, but am really proud.

Would love suggestions on how to move forward on this roadmap.

https://preview.redd.it/1r4kd0wdhcbh1.png?width=398&format=png&auto=webp&s=6638bec438778105638adcee0d5f535e3ff86bb7

https://preview.redd.it/1xfk33wdhcbh1.png?width=402&format=png&auto=webp&s=402aae9200b9ef61c25d86f2e9b4fa6022c56bfc

reddit.com
u/SoloLeveller07 — 1 day ago
▲ 28 r/raylib+5 crossposts

I finally finished version 1.04 of my first larger game made with raylib + C++.

It's a fast-paced arcade game where you dodge enemies, collect powerups, survive boss fights, and unlock higher levels.

Features:

  • Boss fight system with projectile attacks
  • Multiple enemy types
  • Powerups (shield, speed boost, double points, extra life)
  • Level progression + save system
  • Gamepad support
  • Audio + UI system
  • Dynamic difficulty scaling
  • State-based game flow (menu, pause, countdown, bossfight, game over, etc.)

The whole project was built from scratch in C++ using raylib.

Working on this taught me a lot about:

  • game loops
  • collision systems
  • entity/state management
  • timers
  • balancing difficulty
  • organizing a larger codebase

Big thanks to u/leifbron for helping me normalize the player movement vector properly — movement feels much better now.

Some parts are definitely still messy, but finishing a complete playable project feels great.

Would love feedback from other raylib devs.

Link to game: https://pingponger231.itch.io/avoid-b

u/Pale-Candidate-4122 — 2 days ago
▲ 9 r/raylib+3 crossposts

My first C and raylib project

Coming from working in python and rust, this was filled with various emotions. Some good, some bad (build system).

I had made a rust TUI for my car diagnositcs. I've now replaced that with a GUI built with raylib and C.

The project itself is not too complex. I liked that I had a good enough idea about where my variables exist.

Other things I found interesting:

- manually lock and unlock mutexes rather than having them "wrapped" like rust. I believe there are ways to automate with attributes but I haven't learned that yet

- static vars because no OOP. particularly useful for storing animation state

- build system. I had a rough experience with cmake but got it to work. I want to build everything manually to learn how exactly its all being put together.

- side note: inspired confidence to dive into buildoot and optimize my pi image. Now boots 7s faster than my previous regular image process and manual flows.

Since I like driving manuals and learning about efficiency and whatnot, learning C was (still stressful) but rewarding. My previous project was a rust TUI, and now its "deoxidized" to this C project. Roller coaster ride.

youtu.be
u/f2se — 2 days ago
▲ 340 r/raylib+3 crossposts

Hows this for an enemy unit? (No animation only rigged physics textures) Procedural destruction meaning u break him apart piece by piece , 28 parts to destroy

u/DapperAd2798 — 4 days ago
▲ 23 r/raylib

Why is this happening?

I used to use Raylib 5.5 up until but recently updated raylib to the latest, Up until now raylib always let some other window pop infront it but now i doesn't let any kind of window place on to itself, i haven't changed anything related to screen or even the file browser pop up, here is the source

I actually managed to fix it, also there is also issue created regarding the issue too
issue: https://github.com/raysan5/raylib/issues/5854
my fix: https://github.com/Careoke/raylib/commit/194867aa55146d4d989586e59e4a6890181e7435

u/Tillua467 — 3 days ago
▲ 90 r/raylib+1 crossposts

curvature of space

One night, I decided to create a simulation that would show how space curves based on an object's mass, and I didn't finish the project until morning. I spent a long time selecting the colors to ensure it wouldn't be hard to look at.

source code: https://github.com/formodx/curvature-of-space

u/Fit-Life-8239 — 4 days ago
▲ 1 r/raylib

How can I build a file browser in raygui?

I already implemented logic to select paths, expand them etc. But the issue is creating a user interface. I was thinking of creating a ScrollPanel for this like a regular text editor would. It would have text showing the file/directory name and if it's a directory it will have a '+' icon next to it which can be toggled to expand that directory.

Since I'm just learning about raylib and raygui I don't know most controls. I played around with some of them but still have no idea how to implement this. Any help or direction?

Example

reddit.com
u/avestronics — 3 days ago
▲ 46 r/raylib

My Raylib Blackhole for 2d game with resource limitations

While maybe not scientifically accurate, I'm pleased with my 2d game's resource-strapped depiction of a blackhole.

There are no sprites or animations in use here. It's all just shapes and colours in code. This is a recording of testing on a psp console.

u/c_whittles — 5 days ago
▲ 53 r/raylib

CRT Shader + 2D lighting with normals for proper light reaction is AWESOME! Really happy with the result with this custom lighting shader!! (Shader in the description)

Here I am showing a part of my game that I am working on. It's a combination of Raylib 6.0 C#, ECS, AI GOAP behaviour and 2D lighting with albedo, normal and emission.

Let me know if you want a more extensive tutorial about this. Will be with C#. But for people interested in the shader it's here. Because I primary focus on modern hardware it's only version 3.3 :)

#version 330

in vec2 fragTexCoord;
out vec4 finalColor;

uniform sampler2D texture0;
uniform sampler2D uNormalTex;
uniform sampler2D uEmissionTex;

uniform vec2 uResolution;
uniform vec3 uAmbient;
uniform float uNormalYSign;
uniform float uEmissionStrength;
uniform float uNormalStrength;
uniform float uSpecularStrength;
uniform float uSpecularPower;

#define MAX_LIGHTS 32
#define LIGHT_DIR 0
#define LIGHT_OMNI 1
#define LIGHT_SPOT 2

uniform int uNumLights;

uniform vec4 uLightPosType[MAX_LIGHTS];
uniform vec4 uLightColorEnergy[MAX_LIGHTS];
uniform vec4 uLightDirRange[MAX_LIGHTS];
uniform vec4 uLightParams[MAX_LIGHTS];

float RangeAttenuation(float distance2D, float range, float falloff)
{
    if (range <= 0.0)
    {
        return 0.0;
    }

    float normalDistance = clamp(distance2D / range, 0.0, 1.0);
    float attenuation = 1.0 - normalDistance;

    return pow(attenuation, max(falloff, 0.0001));
}

void main()
{
    vec4 albedoSample = texture(texture0, fragTexCoord);
    vec3 albedo = albedoSample.rgb;
    vec3 emission = texture(uEmissionTex, fragTexCoord).rgb * uEmissionStrength;

    vec3 normal = texture(uNormalTex, fragTexCoord).rgb * 2.0 - 1.0;

    if (dot(normal, normal) < 0.0001)
    {
        normal = vec3(0.0, 0.0, 1.0);
    }

    normal.y *= uNormalYSign;
    normal = normalize(normal);

    vec2 pixelPosition = vec2(gl_FragCoord.x, uResolution.y - gl_FragCoord.y);

    vec3 totalLight = uAmbient;
    vec3 totalSpecular = vec3(0.0);
    vec3 viewDirection = vec3(0.0, 0.0, 1.0);

    for (int i = 0; i < uNumLights; i++)
    {
        int lightType = int(uLightPosType[i].w + 0.5);

        vec3 lightPosition = uLightPosType[i].xyz;
        vec3 lightColor = uLightColorEnergy[i].rgb;
        float lightEnergy = uLightColorEnergy[i].w;

        vec3 rawLightTravelDirection = uLightDirRange[i].xyz;
        vec3 lightTravelDirection = vec3(0.0, 0.0, -1.0);

        if (dot(rawLightTravelDirection, rawLightTravelDirection) > 0.000001)
        {
            lightTravelDirection = normalize(rawLightTravelDirection);
        }

        float lightRange = uLightDirRange[i].w;

        float falloff = uLightParams[i].x;
        float innerCone = uLightParams[i].y;
        float outerCone = uLightParams[i].z;

        vec3 lightDirection;
        float attenuation = 1.0;

        if (lightType == LIGHT_DIR)
        {
            lightDirection = normalize(-lightTravelDirection);
        }
        else
        {
            vec2 delta2D = lightPosition.xy - pixelPosition;

            vec3 delta3D = vec3(
                delta2D.x,
                delta2D.y,
                max(lightPosition.z, 0.001)
            );

            lightDirection = normalize(delta3D);

            float distance2D = length(delta2D);
            attenuation = RangeAttenuation(distance2D, lightRange, falloff);

            if (attenuation <= 0.0)
            {
                continue;
            }

            if (lightType == LIGHT_SPOT)
            {
                vec3 fromLightToFragment = normalize(vec3(
                    pixelPosition.x - lightPosition.x,
                    pixelPosition.y - lightPosition.y,
                    -max(lightPosition.z, 0.001)
                ));

                float cone = dot(fromLightToFragment, lightTravelDirection);
                float spotAmount = smoothstep(outerCone, innerCone, cone);

                attenuation *= spotAmount;

                if (attenuation <= 0.0)
                {
                    continue;
                }
            }
        }

        float lambert = max(dot(normal, lightDirection), 0.0);

        float normalInfluence = mix(1.0, lambert, clamp(uNormalStrength, 0.0, 1.0));

        vec3 diffuse = lightColor * lightEnergy * normalInfluence * attenuation;
        totalLight += diffuse;

        vec3 halfDirection = normalize(lightDirection + viewDirection);
        float specular = pow(max(dot(normal, halfDirection), 0.0), uSpecularPower);
        totalSpecular += lightColor * lightEnergy * specular * attenuation * uSpecularStrength;
    }

    vec3 finalRgb = albedo * totalLight + totalSpecular + emission;
    finalColor = vec4(finalRgb, albedoSample.a);
}

Also for the correction when you flip or rotate the normal here is that simple shader:

#version 330

in vec2 fragTexCoord;
out vec4 finalColor;

uniform sampler2D texture0;

// x = m00
// y = m01
// z = m10
// w = m11
uniform vec4 uNormalTransform;

void main()
{
    vec4 sampleColor = texture(texture0, fragTexCoord);

    if (sampleColor.a <= 0.001)
    {
        discard;
    }

    vec3 normal = sampleColor.rgb * 2.0 - 1.0;

    vec2 transformedNormal = vec2(
        normal.x * uNormalTransform.x + normal.y * uNormalTransform.y,
        normal.x * uNormalTransform.z + normal.y * uNormalTransform.w
    );

    normal.xy = transformedNormal;
    normal = normalize(normal);

    finalColor = vec4(normal * 0.5 + 0.5, sampleColor.a);
}
u/Dear-Beautiful2243 — 6 days ago
▲ 29 r/raylib

Wall to Wall fantasy, new unit for Archmage faction!

😂 A new, expensive unit for the Archmage at rank 2. As you can imagine, it's expensive, but worth it.

It's also currently the only unit in the game that can rain down projectiles like that.

u/No_Salamander_4348 — 5 days ago
▲ 149 r/raylib

Simple Raycaster in C++ using Raylib

Very Simple Raycaster in C++ using Raylib.

Features:

Untextured Walls

Minimap

To add:

Textured Walls

Sprites

Agents

u/vector_not_blue — 7 days ago
▲ 4 r/raylib

Breaking Changes in Raylib 6.0❓ (Freezing Window)

For the last 3 days I would fight against my computer trying to figure out why Raylib 6.0 is not working at all. Everything would compile fine and debugger starts, window is created, no errors at all, however then the window remains frozen and it won't ever be refreshed. Entering the main loop works fine but since window is frozen essentially there is not updating and event processing going on.

I don't remember exactly if this was a problem right form the start (I think that I tried some quick samples and they worked - though I am not sure) but the point is that the definitely for the last few days I was unable to figure out what was the cause. Things I tried:
• I downloaded the released version from Github (MSVC 64) (directly linking to it didn't work).
• I reinstalled VCPKG and done a clean build from source.
• I reinstalled VisualStudio2026 from scratch.

My last resort was to prompt Claude for ideas and it said to use GLFW to poll events and swap buffers, good thing is that Raylib provides those so no extra glfw linking was needed.

InitWindow(800, 600, "raylib transform sample");
SetTargetFPS(0); // this has no effect
while (!WindowShouldClose()) {
ClearBackground(BLACK);
BeginDrawing();
DrawText("hello", 10, 10 + std::sinf(GetTime() * 5.0f) * 10, 20, WHITE);
EndDrawing();

// ⚠ this line is important because it unfreezes the window
SwapScreenBuffer();
}

I am not sure if this is a special needed for my system, or is something that changed in recent Raylib versions, but anyway I will mention it just in case someone stumbles on this problem at some point.

I see in the Raylib source that SwapScreenBuffer is supposed to be called only once on EndDrawing, but it depends on the compile flag SUPPORT_CUSTOM_FRAME_CONTROL. I am not sure how this is supposed to alter the standard behavior.
https://github.com/raysan5/raylib/blob/master/src/rcore.c#L883

Anyway, I hope you find this info useful.

u/Still_Explorer — 6 days ago
▲ 10 r/raylib

Is it possible to have constant frame-pacing on PCs (with raylib)

I'm interested in getting constant frame-pacing. It's part curiosity and part perfectionism, is it possible on PC nowadays or is it just a pipedream that I should give up?

reddit.com
u/Gold-Bookkeeper-8792 — 8 days ago