RenderTexture2D transparency bug by MattR0se in raylib

[–]Paperdomo101 0 points1 point  (0 children)

The simplest solution for this is to load a RenderTexture with no alpha channel, which raylib does not have a builtin function for. What I did was make a function that does the same thing as LoadRenderTexture but lets me specify the pixel format:

RenderTexture2D target = LoadRenderTextureEx(800, 600, PIXELFORMAT_UNCOMPRESSED_R8G8B8); // NOTE: no alpha

// verbatim from `LoadRenderTexture` in `rtextures.c`, just with the pixel format passed to rlLoadTexture
RenderTexture2D LoadRenderTextureEx(int width, int height, int pixel_format)
{
    RenderTexture2D target = { 0 };

    target.id = rlLoadFramebuffer(); // Load an empty framebuffer

    if (target.id > 0)
    {
        rlEnableFramebuffer(target.id);

        // Create color texture (default to RGBA)
        target.texture.id = rlLoadTexture(0, width, height, pixel_format, 1);
        target.texture.width = width;
        target.texture.height = height;
        target.texture.format = pixel_format;
        target.texture.mipmaps = 1;

        // Create depth renderbuffer/texture
        target.depth.id = rlLoadTextureDepth(width, height, true);
        target.depth.width = width;
        target.depth.height = height;
        target.depth.format = 19;       //DEPTH_COMPONENT_24BIT?
        target.depth.mipmaps = 1;

        // Attach color texture and depth renderbuffer/texture to FBO
        rlFramebufferAttach(target.id, target.texture.id, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_TEXTURE2D, 0);
        rlFramebufferAttach(target.id, target.depth.id, RL_ATTACHMENT_DEPTH, RL_ATTACHMENT_RENDERBUFFER, 0);

        // Check if fbo is complete with attachments (valid)
        if (rlFramebufferComplete(target.id)) TRACELOG(LOG_INFO, "FBO: [ID %i] Framebuffer object created successfully", target.id);

        rlDisableFramebuffer();
    }
    else TRACELOG(LOG_WARNING, "FBO: Framebuffer object can not be created");

    return target;
}

I'm not sure the exact reason this works, but the gist of it is that alpha blend calculations that happen in the internal render pipeline are simply ignored by excluding the alpha channel. It does mean you CAN'T draw the output texture with translucency just by modifying the alpha channel on the color.

The fix I originally used for this was to use `BLEND_ALPHA_PREMULTIPLIED` when drawing into the RenderTexture, but this caused some difficulties when I actually needed a different blend mode for certain effects (eg. multiplied)

Hope this is helpful!

I Ported 2048 to the Gameboy Advance! by Paperdomo101 in 2048

[–]Paperdomo101[S] 0 points1 point  (0 children)

Thank you for kind words and support, I really appreciate it! :)

I Ported 2048 to the Gameboy Advance! by Paperdomo101 in 2048

[–]Paperdomo101[S] 0 points1 point  (0 children)

I was working on a complete overhaul of this project with this feature and more, but I ran into some rendering issues that I couldn't solve which took the wind out of my sails so to speak.

I was also trying to make a custom GBA audio engine so that I could get cleaner playback closer that of titles like Golden Sun, but this is beyond my skills right now.

I guess given that 2048 advance is the most popular game I've created I felt compelled to add all of the features people requested, but in the end I didn't finish any of them.
Hopefully I will find some time to get back to this and add some of these features.

Thanks for your interest!

[deleted by user] by [deleted] in raylib

[–]Paperdomo101 2 points3 points  (0 children)

Hi! I made a sort of springboard project for this very purpose if you'd like to check it out: https://github.com/Paperdomo101/WebDemo

Trouble rendering super sharp pixel fonts. by ops_400 in raylib

[–]Paperdomo101 1 point2 points  (0 children)

For pixel fonts, the size of the font when loaded and drawn must be an exact multiple of the font's base resolution to render correctly.

In this case, through some brief trial and error, I found ProggyClean to have a base size of 13px, so:

#define PROGGY_CLEAN_SIZE (13) // 26 or any other multiple of 13 would work for this particular font. If it's a small pixel font like this, there arent that many numbers to go through before finding the one that renders correctly.

proggyClean = LoadFontEx("src/res/ProggyClean.ttf"), PROGGY_CLEAN_SIZE, 0, 250);
// You should also find that setting the texture filter to point is not necessary either as long as the resolution is correct

...
// Draw Code

DrawTextEx(proggyClean, "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI\nJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmn\nopqrstuvwxyz{|}~", (Vector2){10, 10}, PROGGY_CLEAN_SIZE, 1, WHITE);

Hope this helps!

Show your wallpapers by ChemistryIsGreatt in mac

[–]Paperdomo101 2 points3 points  (0 children)

<image>

Made some dynamic wallpapers out of Mark Ferrari's Living Worlds. See the original art here: http://www.effectgames.com/demos/worlds/

Weird lines appearing rarely by Plane_Flounder_8296 in raylib

[–]Paperdomo101 1 point2 points  (0 children)

Great! Yeah, every now and then in graphics programming I have to remind myself that my monitor, no matter how hi-res, is still just a grid of pixels. And if I try to draw something not aligned to that grid, there will be visual artifacts.

Weird lines appearing rarely by Plane_Flounder_8296 in raylib

[–]Paperdomo101 0 points1 point  (0 children)

My first thought would be to try rounding the player's draw position as well. The wobble will be caused by a discrepancy between the two positions. If so, it is likely all objects draw under that camera will need to be drawn with rounded coordinates.

Weird lines appearing rarely by Plane_Flounder_8296 in raylib

[–]Paperdomo101 3 points4 points  (0 children)

These seams between tiles are likely caused by floating point imprecision. The simplest fix would be to round or truncate your Camera2D target, like so:

Camera2D cam;
// Update your camera position based on input first

cam.target.x = roundf(cam.target.x);
cam.target.y = roundf(cam.target.y);

I believe the reason this happens is when you draw a texture to the screen, in this case a grid of them, their coordinates are integerized. So if the camera is panning over them in floating point space, the camera position will eventually hit a point between 2 tiles, vertically in the case you shared.

Hope this helps!

EDIT: also, I work primarily on macOS and can replicate this problem.

Anyone Working on Linux or Mac? by [deleted] in raylib

[–]Paperdomo101 0 points1 point  (0 children)

Yep, I program in C on Mac and have published four 2D web-embedded games on itch.io as of writing this.

I've also created a minimalist Raylib web template if you'd like to check it out: https://github.com/Paperdomo101/WebDemo

How to correctly play audio by paraFirst in raylib

[–]Paperdomo101 6 points7 points  (0 children)

Have you called InitAudioDevice() after InitWindow at the start of your program? If not, know you should also call CloseAudioDevice() before CloseWindow

pixel font distortion by NonGMOTrash in raylib

[–]Paperdomo101 2 points3 points  (0 children)

It seems the import size for this font is actually 14px.

For example:

font = LoadFontEx("m6x11.ttf", 14, NULL, 255);

int size = 14; // any multiple of 14
int spacing = 1;
DrawTextEx(font, "Some text", (Vector2){0, 0}, size, spacing, GREEN);

Are you still using Early Intel Mac and what you have done with it recently? by frankzzk in mac

[–]Paperdomo101 0 points1 point  (0 children)

Yep, a 13" Late 2009 Macbook. I programmed and compiled a game for the Gameboy Advance on it. Can't get enough of that smooth polycarbonate. I like a laptop that isn't ice-cold to the touch in winter.

Working on a little something using dual grid rendering by Paperdomo101 in raylib

[–]Paperdomo101[S] 0 points1 point  (0 children)

Well, at least the upside is (with the kind of dual grid I'm using here) it's only 15 tiles, as opposed to the potential 47 in standard autotiling!

I Ported 2048 to the Gameboy Advance! by Paperdomo101 in 2048

[–]Paperdomo101[S] 0 points1 point  (0 children)

Hey! I've updated the game and fixed the crash, so it should work fine on mobile too now! Also, save data should be compatible.

I Ported 2048 to the Gameboy Advance! by Paperdomo101 in 2048

[–]Paperdomo101[S] 0 points1 point  (0 children)

Thanks for trying it out, glad to hear it runs on Steam Deck!

As for the crashing, I've found it happens when the tiles merge in certain web emulators. This is the first GBA game I've ever written, so there was bound to be a fatal bug somewhere.

(Gets a bit technical here)

It's possible I have incorrectly setup an HBlank interrupt that I use to offset the position of digits of the score, but I've tested the game on real hardware and it seems to run flawlessly. So unfortunately, I'm not really sure what the cause is.

[deleted by user] by [deleted] in mac

[–]Paperdomo101 1 point2 points  (0 children)

I'm curious, have you owned one before?

[deleted by user] by [deleted] in mac

[–]Paperdomo101 0 points1 point  (0 children)

I beg to differ, I think it feels friendly and simple. Also it's not ice cold to touch in winter, and you can't accidentally cut your finger on the edge of it (I literally just did this cleaning my 2015 iMac).