libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.98k stars 1.84k forks source link

[SDL3] Bug/OSX: Metal renderer textures are drawn with darker colors #9879

Closed MrOnlineCoder closed 5 months ago

MrOnlineCoder commented 5 months ago

OS: Mac OS X 14.4.1 Compiler:

Apple clang version 15.0.0 (clang-1500.3.9.4)
Target: arm64-apple-darwin23.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

SDL version: SDL3

When loading textures with SDL_image and rendering them, they appear much darker if the current renderer is the "metal" one. Changing it to another renderer like "opengl" works fine and the textures are drawn correctly.

Reproduce code:

#include <SDL3/SDL.h>
#include <SDL3_image/SDL_image.h>

int main()
{
    SDL_Init(SDL_INIT_VIDEO);

    IMG_Init(IMG_INIT_JPG | IMG_INIT_PNG);

    SDL_Window *window = SDL_CreateWindow(
        "Test",
        640,
        480,
        0);

    SDL_Renderer *renderer = SDL_CreateRenderer(
        window,
        "metal"); //change to opengl to fix

    SDL_RendererInfo info;
    SDL_GetRendererInfo(renderer, &info);

    printf("Renderer: %s\n", info.name);

    SDL_Texture *texture = IMG_LoadTexture(renderer, "test.jpg");

    while (true)
    {
        SDL_Event event;
        if (SDL_PollEvent(&event))
        {
            if (event.type == SDL_EVENT_QUIT)
            {
                break;
            }
        }

        SDL_RenderClear(renderer);
        SDL_RenderTexture(renderer, texture, NULL, NULL);
        SDL_RenderPresent(renderer);
        SDL_Delay(1000 / 60);
    }

    return 0;
}

Attaching two screenshots from my machine, first is metal, second is opengl (no image or color corrections weren't applied to the screenshots, surely).

Passing NULL to SDL_CreateRenderer as a name also does not solve the problem, as metal backend is selected by default in that case.

Screenshot 2024-05-25 at 00 47 52 Screenshot 2024-05-25 at 00 48 18
slouken commented 5 months ago

Can you attach a link to test.jpg?

Thanks!

MrOnlineCoder commented 5 months ago

@slouken yea, sure, sorry, forgot that one. Hope Github will preserve the file completely, however it works with basically any JPG or PNG file. test

kieselsteini commented 5 months ago

Hey there. I can confirm this issue as well. Using the metal renderer on macOS will result in much darker colors. Even checked the master today. This is the exact same code running with different renderers on macOS 14.5

sdl3_opengl_metal