Skip to content

Commit 27af359

Browse files
authored
[rlgl] Preserve texture on mode switching (#4364)
* Fix textures on draw mode switch * formatting fix * ident
1 parent e1ec595 commit 27af359

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

examples/textures/textures_polygon.c

+1-5
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2 *points, Vector2
117117
{
118118
rlSetTexture(texture.id);
119119

120-
// Texturing is only supported on RL_QUADS
121-
rlBegin(RL_QUADS);
120+
rlBegin(RL_TRIANGLES);
122121

123122
rlColor4ub(tint.r, tint.g, tint.b, tint.a);
124123

@@ -132,9 +131,6 @@ void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2 *points, Vector2
132131

133132
rlTexCoord2f(texcoords[i + 1].x, texcoords[i + 1].y);
134133
rlVertex2f(points[i + 1].x + center.x, points[i + 1].y + center.y);
135-
136-
rlTexCoord2f(texcoords[i + 1].x, texcoords[i + 1].y);
137-
rlVertex2f(points[i + 1].x + center.x, points[i + 1].y + center.y);
138134
}
139135
rlEnd();
140136

src/rlgl.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,7 @@ void rlBegin(int mode)
14591459
// NOTE: In all three cases, vertex are accumulated over default internal vertex buffer
14601460
if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode != mode)
14611461
{
1462+
int currentTexture = RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId;
14621463
if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount > 0)
14631464
{
14641465
// Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4,
@@ -1481,13 +1482,14 @@ void rlBegin(int mode)
14811482

14821483
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode = mode;
14831484
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount = 0;
1484-
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId = RLGL.State.defaultTextureId;
1485+
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId = currentTexture;
14851486
}
14861487
}
14871488

14881489
// Finish vertex providing
14891490
void rlEnd(void)
14901491
{
1492+
rlSetTexture(RLGL.State.defaultTextureId);
14911493
// NOTE: Depth increment is dependant on rlOrtho(): z-near and z-far values,
14921494
// as well as depth buffer bit-depth (16bit or 24bit or 32bit)
14931495
// Correct increment formula would be: depthInc = (zfar - znear)/pow(2, bits)

0 commit comments

Comments
 (0)