From 2554dcba9b9175781ba042b7d13c9a80d7d5fb6d Mon Sep 17 00:00:00 2001 From: Maicon Santana Date: Wed, 24 Sep 2025 09:22:03 +0100 Subject: [PATCH] fix rlSetTexture not overriding default mode (#5200) --- src/rlgl.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/rlgl.h b/src/rlgl.h index e58302ceb..7db05251d 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -1067,6 +1067,7 @@ typedef struct rlglData { Matrix stack[RL_MAX_MATRIX_STACK_SIZE];// Matrix stack for push/pop int stackCounter; // Matrix stack counter + unsigned int currentTextureId; // Current texture id to be used on glBegin unsigned int defaultTextureId; // Default texture used on shapes/poly drawing (required by shader) unsigned int activeTextureId[RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS]; // Active texture ids to be enabled on batch drawing (0 active by default) unsigned int defaultVShaderId; // Default vertex shader id (used by default shader program) @@ -1485,8 +1486,8 @@ void rlBegin(int mode) if (RLGL.currentBatch->drawCounter >= RL_DEFAULT_BATCH_DRAWCALLS) rlDrawRenderBatch(RLGL.currentBatch); RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode = mode; - RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount = 0; - RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId = RLGL.State.defaultTextureId; + RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId = RLGL.State.currentTextureId; + RLGL.State.currentTextureId = RLGL.State.defaultTextureId; } } @@ -1651,6 +1652,7 @@ void rlSetTexture(unsigned int id) { rlDrawRenderBatch(RLGL.currentBatch); } + RLGL.State.currentTextureId = RLGL.State.defaultTextureId; #endif } else @@ -1658,6 +1660,7 @@ void rlSetTexture(unsigned int id) #if defined(GRAPHICS_API_OPENGL_11) rlEnableTexture(id); #else + RLGL.State.currentTextureId = id; if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId != id) { if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount > 0) @@ -1676,6 +1679,9 @@ void rlSetTexture(unsigned int id) RLGL.State.vertexCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment; RLGL.currentBatch->drawCounter++; + + RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode = RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 2].mode; + } } @@ -2257,6 +2263,7 @@ void rlglInit(int width, int height) // Init default white texture unsigned char pixels[4] = { 255, 255, 255, 255 }; // 1 pixel RGBA (4 bytes) RLGL.State.defaultTextureId = rlLoadTexture(pixels, 1, 1, RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 1); + RLGL.State.currentTextureId = RLGL.State.defaultTextureId; if (RLGL.State.defaultTextureId != 0) TRACELOG(RL_LOG_INFO, "TEXTURE: [ID %i] Default texture loaded successfully", RLGL.State.defaultTextureId); else TRACELOG(RL_LOG_WARNING, "TEXTURE: Failed to load default texture");