r/raylib • • 27m ago

Drawing textures randomly works and doesn't when trying to render a linked-list of elements

1 Upvotes

I'm trying to make a toy image editor using Raylib and C++ and ran into this problem.

When I try to render the layers of my project, there's a chance that they just wouldn't render at all, and yes the textures are loaded in.

I have a Canvas class that holds a reference to the first element of the linked-list where the layers of the project are. This class also has a method to add a new element to the list.

Canvas::Canvas(int width, int height){
    rt = LoadRenderTexture(width, height);
    rec =  {0.0f, 0.0f, (float)width, (float)(-height)};
} 

void Canvas::AddLayer(LayerObject* newLayer){
    if (newLayer == nullptr) {
        std::cerr << "[WARNING] Trying to add a null layer\n";
        return;
    }

    if (layers == nullptr) {
        layers = newLayer;
        return;
    }
    
    LayerObject* it = layers;
    while (it->next != nullptr){
        it = it->next;
    }
    it->next = newLayer;
    it->next->prev = it;

}

void Canvas::DrawLayers(){
    BeginTextureMode(rt);
        ClearBackground(WHITE);
        LayerObject* it = layers;
        while (it != nullptr){
            it->Draw();
            it = it->next;
        }
    EndTextureMode();
}

// ...

I'm suspecting that the Add() method is the culprit, but when I use the Add method in the constructor for debugging purposes, it works completely fine and renders the layer 100% of the time.

I tried checking to see if the DrawLayers() method was the culprit but printing how many layers the loop rendered turned out fine.

Here are some important methods of my RenderLayer

RasterLayer::RasterLayer(Vector2 position, const char* path){
    texture = LoadTexture(path);
    position = position;
    size = (Vector2){(float)texture.width, (float)texture.height};
}

void RasterLayer::Draw(){
    // TODO: add rotation
    //       add cropping
    //       use DrawTexturePro
    DrawTexture(texture, position.x, position.y, WHITE);
}

Any help would be appreciated. Thanks!


r/raylib • • 4h ago

Is this game better off with Raylib or Unity?

Thumbnail
gallery
13 Upvotes

I'm wanting to make a grid-based, proc-gen RPG that's resembles DOOM or Daggerfall (3d world, 2d sprites) but navigate with grid-based walking like in Eye of the Beholder. It would have modern retro graphics that will require lighting, weather, and shadows (see my four Daggerfall Unity screenshots for my vision in art, which uses the amazing DREAM mod.). I'm familiar with Raylib and did a few 2D games with it in C++. I love it. I found BigFoot76's rlights.h that really helps with lighting and shadows with my simple tests. But I'm just wondering, will I have the best luck in Raylib or Unity with this game? I'm sure you're not biased at all here, and can maybe share how Raylib stacks up with 3D. I think one thing that attracts me to wanting to use Raylib is the proc-gen is done at runtime with grid-based layouts, so the project may be very code-centric. I do enjoy how Raylib lets you focus on code.

I grew up in the days when Unity was just starting and did coding by hand, starting with DirectDraw. So, Raylib brings that sense of joy back to programming. I'm for speed, but I'm also a realist that I won't be taking advantage of Untiy's level editor since most of the proc-gen is done in code for both interiors and exteriors. I don't know what tools I would be benefiting from if I'm not using the level editor.


r/raylib • • 4h ago

My First Raylib Game - Snake

Post image
9 Upvotes

r/raylib • • 23h ago

[Free] Sci-fi / cyberpunk UI frames as SVG + PNG - easy 9-slice with DrawTexturePro in raylib

1 Upvotes

Here's a free UI kit that maps cleanly onto raylib's DrawTexturePro 9-slice approach: the frames ship as transparent PNGs you can load with LoadTexture, and the source SVG keeps the 9-slice groups separate if you need a different export scale. No font dependency - the shapes carry the look, so it drops in next to whatever font you already use.

Free (commercial use, no attribution): https://craftpixel.itch.io/free-cyberpunk-sci-fi-ui-starter-kit-vector-svg

Full 10-pack set at 80% off for Black Friday / Cyber Monday: https://itch.io/s/221135/ultimate-cyberpunk-and-sci-fi-ui-mega-bundle-10-in-1


r/raylib • • 1d ago

I made a lightweight shader helper for raylib 3d - RSF3D

Post image
11 Upvotes

Hi everyone!

  • I have been working on RSF3D (Raylib Shader Forward 3D), a lightweight, easy-to-use that helps to add lights, fog, and skybox.

  • Features:

    • Blinn-Phong and Gouraud.

    • Point, directional, spot lights.

    • Linear, exponential and exponential squared fogs.

    • Skybox.

  • My goal is to provide a simple helper for games, educations, simulators,... without bringing a complicated rendering.

  • GitHub: RSF3D - Nam-python

I'd love to hear your feedback, suggestions and ideas for improvements!

Thanks!


r/raylib • • 1d ago

Classic 2048 game variant I made in C and Raylib.

Thumbnail
gallery
22 Upvotes

Move tiles with the arrow keys. Matching tiles can merge, and a merge can trigger further merges in the same move: for example, 2 2 4 8 becomes _ _ _ 16 directly in a single right click rather than _ 4 4 8.

Other tiles can block movement and merging. For example, 2 4 2 _ becomes 2 4 _ 2 instead of _ 2 4 2 as the end 2 blocks preceding 2 4 from sliding to the right, while 4 8 _ _ becomes 4 _ _ 8 instead of _ _ 4 8 as 8 blocks 4 from sliding to the right.

check out the code on github.


r/raylib • • 2d ago Bravo

Made this raylib game in C about throwing cubes at cats

Post image
20 Upvotes

So in the game you can throw this cube at the cat.

There is also a fence so you don't start standing on nothing, and of course, a ground.

It's still in beta but here's the repo:

https://github.com/donutoreocomputer-arch/meow-cubes


r/raylib • • 3d ago

I wrote flappy bird game on my own raylib ecs engine

89 Upvotes

r/raylib • • 4d ago

Four single-header helpers and a six-platform ship template for raylib C games

17 Upvotes

Hi all,

I've published five small MIT-licensed add-ons for raylib games written in C. Each has a demo that runs in the browser.

  • raylib-canvas-kit: draw at one fixed resolution and show it at any window size (letterbox, pixel-perfect, fill or stretch), with mouse and touch mapped back. One 130-line header. Demo

  • raylib-touch-kit: an on-screen analog stick and buttons for phones and tablets. Multi-touch, drawn with shapes, no assets. One header. Demo

  • raylib-debug-kit: a JSON-lines event log, screenshots on demand and seeded repeatable runs, switched on by command-line flags. One header. Demo

  • raylib-dev-kit: developer modes built into the game: a sound board, an asset gallery and your own sandboxes. One header. Demo

  • raylib-ship-kit: a template that builds one C codebase for macOS, Windows, Linux, the browser, iPhone and iPad with one command each, through to App Store review. Demo

All five are built against raylib 6.2. Feedback and bug reports are welcome.


r/raylib • • 5d ago

I've just released CArgo Bay 2000, a puzzle game with robots and boxes!

19 Upvotes

Hello everyone! :D

I've just released my first game using raylib: Cargo Bay 2000.

Control a robot (from the future) in a warehouse (from the future) and push boxes (also from the future) in a variable-gravity environment.

There's also keycards, pressure plates, elevators and other elements over more than 30 different hand-crafted levels! (but the main catch is the gravity thing, yep!).

It's available (and free!) for Windows and Linux on my itch.io page: https://theisolinearchip.itch.io/cargo-bay-2000

Hope you like it!


r/raylib • • 5d ago

C Programming Blocks is released on Steam (Supports RayLib game programming library)

87 Upvotes

Hello

This is a tool for people who want to enjoy the power of the C programming language (performance and memory efficiency) combined with the simplicity of visual programming while developing games using the RayLib game programming library.

Steam Page: Save 40% on C Programming Blocks on Steam

Note: The software is developed using the Ring programming language based on the PWCT2 source code.

PWCT2 steam page: Programming Without Coding Technology 2.0 on Steam

Thanks


r/raylib • • 6d ago

Added an infinite repeating background to my 2D engine

24 Upvotes

r/raylib • • 6d ago

Test: Sun/Sky Glade, Water Ripples and Reflection, Colored Light Glints

Thumbnail
youtu.be
8 Upvotes

r/raylib • • 6d ago

Does anyone know how I can do the Texturing Step 5 in Raylib?

480 Upvotes

The original GIF is from Rujik https://x.com/TheRujiK/status/969581641680195585 and ever since he released it, this texturing step has been living in my mind like a mystery. I started messing around with Raylib today and the first ambition I have of implementing is this lizard.

But this step seems like a Step 1. Draw circles Step 2. Add in Details to draw Mona Lisa type of step.

Can anyone elaborate? For example, what raylib methods will be used for making this lizard? Especially the texturing? Thanks!


r/raylib • • 6d ago

Is it possible to use raylib in micropython?

0 Upvotes

Ive seen that raylib also has a python3 port, alongside its many other ports; Ive tried it, and its pretty dang good, easy to use, etcetc. I now have an upcoming embedded project, which uses an esp32, and an external st7789 tft display, and i was wondering if it would be possible to somehow use raylib to draw to that display?


r/raylib • • 7d ago

WhenYour game/scene visuals are so aesthetically pleasing(mathemtical models) that you're immediately accused of AI usage, custom game engine built from scratch with C/Raylib/OpengGL, 2.13 million particles in scene processed every frame by shaders(water, lighting..) custom physics engine

34 Upvotes

https://store.steampowered.com/app/3919630/SINGULARITY_RISING/?beta=1 , Wishlist very early DEV 1 year from release

4 scenes showing
1)physics showing the closed loops physics modes from which enemy units are made,
2)the backgrounds and how scenes will look when its all put together,
3)the physics procedural destruction system,
4)and showing the rigged character model


r/raylib • • 7d ago

Hi guys, Double Degree(Software Engineer/Physics) my first game a 2D CUSTOM GAME from scratch and custom game engine with C/Raylib, in genre of (Terminator 2), showing features of my game, 2D action shooter/platformer, [VERY EARLY DEV], lighting, background, GLSL shaders, game style, watch till end

28 Upvotes

r/raylib • • 7d ago

I wrote a 2D game engine from scratch in a week (C++20, raylib). This is the first game on it

12 Upvotes

r/raylib • • 8d ago

I have some problems with camera, can you please help?

1 Upvotes

I'm experimenting with character movement and camera but this is not looking very good. Can you please help? I'm using raylib.

Here is the source code:

#include <raylib.h>
#include <raymath.h>
#include "main.h"

int main(void) {
  SetConfigFlags(FLAG_VSYNC_HINT);

  InitWindow(screenWidth, screenHeight, "Ashenwood");

  ToggleFullscreen();

  Texture2D tile = LoadTexture("./kenney_tiny-dungeon/Tiles/tile_0049.png");
  Texture2D stone = LoadTexture("./kenney_tiny-dungeon/Tiles/tile_0042.png");
  Player player = { (Rectangle){ (screenWidth - 16.0f)/2.0f, (screenHeight - 16.0f)/2.0f, 16.0f, 16.0f }, LoadTexture("./kenney_tiny-dungeon/Tiles/tile_0097.png"), 50.0f };

  SetTextureFilter(tile, TEXTURE_FILTER_POINT);
  SetTextureFilter(stone, TEXTURE_FILTER_POINT);
  SetTextureFilter(player.tile, TEXTURE_FILTER_POINT);

  Camera2D camera = { 0 };
  camera.target = (Vector2){ player.rec.x + 8.0f, player.rec.y + 8.0f };
  camera.rotation = 0.0f;
  camera.zoom = 5.0f;
  camera.offset = (Vector2){screenWidth/2.0f, screenHeight/2.0f};

  int worldMap[MAP_HEIGHT][MAP_WIDTH];
  for (int i = 0; i < MAP_HEIGHT; i++) {
    for (int j = 0; j < MAP_WIDTH; j++) {
      worldMap[i][j] = GetRandomValue(0, 1);
    }
  }

  SetTargetFPS(60);

  while (!WindowShouldClose()) {
    float deltaTime = GetFrameTime();

    Vector2 direction = { 0 };

    if (IsKeyDown(KEY_DOWN)) direction.y += 1;
    if (IsKeyDown(KEY_UP)) direction.y -= 1;
    if (IsKeyDown(KEY_RIGHT)) direction.x += 1;
    if (IsKeyDown(KEY_LEFT)) direction.x -= 1;

    if (Vector2Length(direction) > 0) {
      direction = Vector2Normalize(direction);

      player.rec.x += direction.x * player.speed * deltaTime;
      player.rec.y += direction.y * player.speed * deltaTime;
    }

    float smoothing = 1.0f - expf(-5.0f * deltaTime);
    camera.target = Vector2Lerp(
        camera.target,
        (Vector2){
            player.rec.x + player.rec.width / 2.0f,
            player.rec.y + player.rec.height / 2.0f
        },
        smoothing
    );

    BeginDrawing();
      ClearBackground(RAYWHITE);
      
      BeginMode2D(camera);
      for (int x = 0; x < MAP_HEIGHT; x++) {
        for (int y = 0; y < MAP_WIDTH; y++) {
          if (worldMap[x][y] == 0) {
            DrawTexture(tile, y * TILE_SIZE, x * TILE_SIZE, WHITE);
          } else if (worldMap[x][y] == 1) {
            DrawTexture(stone, y * TILE_SIZE, x * TILE_SIZE, WHITE);
          }
        }
      }

      DrawTexture(player.tile, player.rec.x, player.rec.y, WHITE);
      
      EndMode2D();
      
    EndDrawing();
  }

  UnloadTexture(tile);
  UnloadTexture(stone);
  UnloadTexture(player.tile);

  CloseWindow();

  return 0;

}

r/raylib • • 8d ago

Jojo's mini game , just make it for fun :)

68 Upvotes

r/raylib • • 9d ago

How to bundle multiple draw calls into a single mesh for 2D games?

1 Upvotes

I'm working on a 2D, chunk tile based game where a lot of tiles can be drawn at a time, depending on the zoom level. currently I'm drawing each tile as a separate call to DrawTexturePro, but this is damaging performance a bit.

In a 3D context, i could easily solve this issue by building a Mesh for each chunk, drawing that single mesh and then recomputing that mesh only when the chunk is modified. However, I don't have access to raylib meshes on a 2D context i believe. So what's the recommended approach?


r/raylib • • 9d ago

Please help me to fix this character's movement!

3 Upvotes

I'm experimenting with character movement and camera but this is not looking very good. Can you please help?

Here is the source code:

#include <raylib.h>

#include <raymath.h>

#include "main.h"

int main(void) {

SetConfigFlags(FLAG_VSYNC_HINT);

InitWindow(screenWidth, screenHeight, "Ashenwood");

ToggleFullscreen();

Texture2D tile = LoadTexture("./kenney_tiny-dungeon/Tiles/tile_0049.png");

Texture2D stone = LoadTexture("./kenney_tiny-dungeon/Tiles/tile_0042.png");

Player player = { (Rectangle){ (screenWidth - 16.0f)/2.0f, (screenHeight - 16.0f)/2.0f, 16.0f, 16.0f }, LoadTexture("./kenney_tiny-dungeon/Tiles/tile_0097.png"), 50.0f };

SetTextureFilter(tile, TEXTURE_FILTER_POINT);

SetTextureFilter(stone, TEXTURE_FILTER_POINT);

SetTextureFilter(player.tile, TEXTURE_FILTER_POINT);

Camera2D camera = { 0 };

camera.target = (Vector2){ player.rec.x + 8.0f, player.rec.y + 8.0f };

camera.rotation = 0.0f;

camera.zoom = 5.0f;

camera.offset = (Vector2){screenWidth/2.0f, screenHeight/2.0f};

int worldMap[MAP_HEIGHT][MAP_WIDTH];

for (int i = 0; i < MAP_HEIGHT; i++) {

for (int j = 0; j < MAP_WIDTH; j++) {

worldMap[i][j] = GetRandomValue(0, 1);

}

}

SetTargetFPS(60);

while (!WindowShouldClose()) {

float deltaTime = GetFrameTime();

Vector2 direction = { 0 };

if (IsKeyDown(KEY_DOWN)) direction.y += 1;

if (IsKeyDown(KEY_UP)) direction.y -= 1;

if (IsKeyDown(KEY_RIGHT)) direction.x += 1;

if (IsKeyDown(KEY_LEFT)) direction.x -= 1;

if (Vector2Length(direction) > 0) {

direction = Vector2Normalize(direction);

player.rec.x += direction.x * player.speed * deltaTime;

player.rec.y += direction.y * player.speed * deltaTime;

}

float smoothing = 1.0f - expf(-5.0f * deltaTime);

camera.target = Vector2Lerp(

camera.target,

(Vector2){

player.rec.x + player.rec.width / 2.0f,

player.rec.y + player.rec.height / 2.0f

},

smoothing

);

BeginDrawing();

ClearBackground(RAYWHITE);

BeginMode2D(camera);

for (int x = 0; x < MAP_HEIGHT; x++) {

for (int y = 0; y < MAP_WIDTH; y++) {

if (worldMap[x][y] == 0) {

DrawTexture(tile, y * TILE_SIZE, x * TILE_SIZE, WHITE);

} else if (worldMap[x][y] == 1) {

DrawTexture(stone, y * TILE_SIZE, x * TILE_SIZE, WHITE);

}

}

}

DrawTexture(player.tile, player.rec.x, player.rec.y, WHITE);

EndMode2D();

EndDrawing();

}

UnloadTexture(tile);

UnloadTexture(stone);

UnloadTexture(player.tile);

CloseWindow();

return 0;

}


r/raylib • • 10d ago

Open Source Western ARPG

63 Upvotes

r/raylib • • 10d ago

I am getting this masking effect for no reason, without even changing a line after compilation

Thumbnail
gallery
10 Upvotes

The first image is how it should look.

The other image is how it looks sometimes when I recompile the same code.

#include <raylib.h>
#include <stddef.h>

typedef struct Task {
  char name[25];
  int start;    // task start time in minutes
  int duration; // in minutes
  Color color;
} Task;

void drawTasks(const Task tasks[], size_t n, Rectangle tl) {
  float unit = tl.width / (24 * 60);
  for (int i = 0; i < n; i++) {
    Rectangle taskRec = {unit * tasks[i].start, tl.y, tasks[i].duration * unit,
                         tl.height};
    DrawRectangleRec(taskRec, tasks[i].color);
  }
}

int main(void) {

  // definition
  constexpr int WIN_WIDTH = 800;
  constexpr int WIN_HEIGHT = 600;
  constexpr char WIN_TITLE[] = "schviz";
  constexpr Color WIN_COLOR = {53, 53, 53, .a = 255};
  constexpr Rectangle TIMELINE_REC = {
      .height = 150, .width = WIN_WIDTH - 2 * 10, .x = 10, .y = 150};
  constexpr Color TIMELINE_COLOR = {212, 194, 252, 255};
  constexpr Task tasks[] = {
      {"Get A Job", 540, 180, (Color){35, 87, 137, 255}},
      {"Break I", 720, 45, (Color){155, 193, 188, 255}},
      {"Break II", 915, 45, (Color){155, 193, 188, 255}},
      {"Low-Level Learning", 765, 60, (Color){255, 208, 0, 255}},
      {"Low-Level Programming", 825, 90, (Color){255, 136, 0, 255}}

  };

  // Game Loop
  InitWindow(WIN_WIDTH, WIN_HEIGHT, WIN_TITLE);
  SetTargetFPS(60);

  while (!WindowShouldClose()) {

    // Drawing
    BeginDrawing();
    ClearBackground(WIN_COLOR);
    DrawRectangleRounded(TIMELINE_REC, .15, 10, TIMELINE_COLOR);
    drawTasks(tasks, 10, TIMELINE_REC);
    EndDrawing();
  }
  CloseWindow();
  return 0;
}