1

When trying to draw Rectangles in RayLib 2.6 I'm finding this "bleeding" effect: bleeding effect

I tried to search for this effect (the one I call bleeding) but I haven't managed to find the correct name for it.

I managed to reproduce it in this minimal code example:

#include <raylib.h>

#define MAP_SIZE 64
#define TILE_SIZE 8

static int map[MAP_SIZE][MAP_SIZE];

static Color mappedColor[] = {
    {255, 0, 0, 255},
    {0, 255, 0, 255},
    {0, 0, 255, 255},
};
#define GetMapColor(c) mappedColor[c]

void Render(float dt)
{
    ClearBackground(BLACK);

    for (int x = 0; x < MAP_SIZE; x++)
        for (int y = 0; y < MAP_SIZE; y++)
            DrawRectangle(x * TILE_SIZE, y * TILE_SIZE, (x + 1) * TILE_SIZE, (y + 1) * TILE_SIZE, GetMapColor(map[x][y]));
}

void CreateMap()
{
    for (int x = 0; x < MAP_SIZE; x++)
        for (int y = 0; y < MAP_SIZE; y++)
            map[x][y] = GetRandomValue(0, 3);
}

int main(int argc, char **argv)
{
    InitWindow(800, 600, "Bleeding");
    SetTargetFPS(60);

    CreateMap();

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

        BeginDrawing();

        Render(dt);

        EndDrawing();
    }

    CloseWindow();

    return 0;
}

Thanks!

Prof. Falken
  • 24,226
  • 19
  • 100
  • 173
Satinxs
  • 13
  • 3
  • Maybe you should ask on their github page too? – Prof. Falken Mar 05 '20 at 15:33
  • I am pretty sure that the effect must be the behaviour of `DrawRectangle`. But on a side note, why do you use `(x + 1) * TILE_SIZE`? I'd expect `(x + 1) * TILE_SIZE -1` instead. – Yunnosch Mar 05 '20 at 15:43
  • @Prof.Falkencontractbreached that was my next step, yeah. Or on Twitter, the author is quite active there. – Satinxs Mar 05 '20 at 17:11
  • @Yunnosch I don't think that's the intended behaviour, I'm specifying an area to draw on, why would it go on infinitely like that? About the (x+1) * TILE_SIZE, this was a quickly put together demo of the effect I want to fix, not necessarily a perfect, logical program :) – Satinxs Mar 05 '20 at 17:11
  • 1
    Yeah, do not bother about my side note. But I really think the behaviour is just the one of the used function. Simply because I did not spot anything in your coordinate math (and I did spend thought on that, hence the side note) or elsewhere in the code. I recommend to dig up the documentation and read it thoroughly. I am not saying the the solution is in there (i.e. I do not mean RTFM), just that it HAS to be in there. I hope I only come over as incoherent, I do not intend to blame you. – Yunnosch Mar 05 '20 at 17:15
  • 1
    @Yunnosch It's okay, I understand perfectly. It's not in the docs, I guess either I'm missing some configuration or It's a bug. Thanks anyway! – Satinxs Mar 05 '20 at 17:19
  • If it's a bug which is going to be fixed, then it's not much point writing an answer here. But if it's some kind of configuration issue or so, you can answer your own question here, since the answer will be valuable for others. – Prof. Falken Mar 06 '20 at 07:56

1 Answers1

0

This is because the DrawRectangle function takes different parameters than this code might expect.

void DrawRectangle(int posX, int posY, int width, int height, Color color)

Note that the 3rd and 4th parameters are width and height, not position coordinates for the other corner.

Change the DrawRectangle call to

DrawRectangle(x * TILE_SIZE, y * TILE_SIZE,
              TILE_SIZE, TILE_SIZE,
              GetMapColor(map[x][y]));

to achieve the desired effect.

Will Bradley
  • 1,733
  • 15
  • 27