raylib icon indicating copy to clipboard operation
raylib copied to clipboard

[rlgl] Textures not working when using RL_TRIANGLES

Open raysan5 opened this issue 9 months ago • 4 comments

As per example textures_poligon.c it should work as expected.

Texture should be assigned to vertex triangles.

This issue could be related to some recent changes that broke batching system and were reverted here: https://github.com/raysan5/raylib/commit/46cd07d2c74742fc7fbd9b0f2fb25cd78cd81b4c

Possible review steps: Compare raylib 5.5 rlgl to current master.

raysan5 avatar Apr 02 '25 17:04 raysan5

Related issue with PR that broke batching system: https://github.com/raysan5/raylib/issues/4347

raysan5 avatar Apr 02 '25 18:04 raysan5

One solution is reordering the rlSetTexture() because rlBegin() resets the current texture to default on mode changing...

    rlBegin(RL_TRIANGLES);
        rlSetTexture(texture.id);
        rlColor4ub(tint.r, tint.g, tint.b, tint.a);

        for (int i = 0; i < pointCount - 1; i++)
        {
            rlTexCoord2f(0.5f, 0.5f);
            rlVertex2f(center.x, center.y);

            rlTexCoord2f(texcoords[i].x, texcoords[i].y);
            rlVertex2f(points[i].x + center.x, points[i].y + center.y);

            rlTexCoord2f(texcoords[i + 1].x, texcoords[i + 1].y);
            rlVertex2f(points[i + 1].x + center.x, points[i + 1].y + center.y);
        }
    rlEnd();

raysan5 avatar Apr 02 '25 18:04 raysan5

I don't have a solution, but I noticed that both rlSetTexture and rlBegin advances RLGL.currentBatch->drawCounter if rlCheckRenderBatchLimit. Maybe only one of them should do it...

brccabral avatar Apr 06 '25 23:04 brccabral

This issue could be related to some recent changes that broke batching system and were reverted here: https://github.com/raysan5/raylib/commit/46cd07d2c74742fc7fbd9b0f2fb25cd78cd81b4c

I bisected between 5.5 and https://github.com/raysan5/raylib/commit/1c4aa1378f61e24b2699b24ce05d5a16db64f380, and it showed me the same commit:

46cd07d2c74742fc7fbd9b0f2fb25cd78cd81b4c is the first bad commit
commit 46cd07d2c74742fc7fbd9b0f2fb25cd78cd81b4c (HEAD)
Author: Ray <[email protected]>
Date:   Fri Mar 21 17:17:45 2025 +0100

    WARNING: REVERTED CHANGE THAT BROKE BATCHING!!! #4849
    
    I'm sorry... I did not detect this change was breaking batching... :(

 src/rlgl.h | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

sleeptightAnsiC avatar Jul 01 '25 18:07 sleeptightAnsiC

I'm afraid it can not see a way to address this case without a considerable internal redesign.

So for now to work, it requires calling rlSetTexture() after rlBegin(RL_TRIANGLES), as illustrated in textures_polygon example.

raysan5 avatar Aug 15 '25 10:08 raysan5