[rlgl] Textures not working when using RL_TRIANGLES
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.
Related issue with PR that broke batching system: https://github.com/raysan5/raylib/issues/4347
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();
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...
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(-)
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.