libsdl-org / SDL

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

[SDL2] [PSP] SDL_RenderGeometry / SDL_RenderGeometryRaw does not render textures and vertices colors properly. #9767

Open antim0118 opened 6 months ago

antim0118 commented 6 months ago

As far as I can understand, SDL_RenderGeometry / SDL_RenderGeometryRaw is supposed to color vertices as a gradient, however in both cases only the last color is used.

Code snippet:

//blue triangle
SDL_Vertex vertex_1 = { {100, 100}, {255, 0, 0, 255}, {1, 1} };
SDL_Vertex vertex_2 = { {200, 100}, {0, 255, 0, 255}, {1, 1} };
SDL_Vertex vertex_3 = { {200, 200}, {0, 0, 255, 255}, {1, 1} }; // <- this color is being used (blue)
SDL_Vertex vertices[] = { vertex_1,vertex_2,vertex_3 };
SDL_RenderGeometry(renderer, NULL, vertices, 3, NULL, 0);

//pink triangle
float xy[6] = { 200, 100, 400, 200, 200, 200 };
SDL_Color colors[3] = {
    {255, 0, 0, 255},
    {255, 255, 0, 255},
    {255, 0, 255, 255} // <- this color is being used (pink)
};
float uv[6] = { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
SDL_RenderGeometryRaw(renderer, NULL, xy, 8, colors, 4, uv, 8, 3, NULL, 1, 1);

Result: image

antim0118 commented 6 months ago

I did some investigation. This bug happens after calling SDL_RenderFillRect. It looks normal when I call SDL_RenderGeometry before SDL_RenderFillRect.

antim0118 commented 6 months ago

Also, I cannot apply textures, it also break the colors.

Code snippet:

SDL_Vertex vertex_0 = { {100, 100}, {255, 0, 0, 255}, {1, 1} };
SDL_Vertex vertex_1 = { {200, 100}, {0, 255, 0, 255}, {1, 1} };
SDL_Vertex vertex_2 = { {200, 200}, {0, 0, 255, 255}, {1, 1} };
SDL_Vertex vertex_3 = { {100, 200}, {0, 0, 255, 255}, {1, 1} };
SDL_Vertex vertices[] = { vertex_0,vertex_1,vertex_2,vertex_3 };
int indices[] = { 0, 1, 2, 2, 3, 0 };
SDL_RenderGeometry(renderer, mTexture, vertices, 4, indices, 6);

image