diff --git a/src/rlgl.h b/src/rlgl.h index 9b94d402c6d2..b0bdc89f39d6 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -1428,6 +1428,7 @@ void rlBegin(int mode) // NOTE: In all three cases, vertex are accumulated over default internal vertex buffer if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode != mode) { + int currentTexture = RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId; if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount > 0) { // Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4, @@ -1450,7 +1451,7 @@ void rlBegin(int mode) 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 = currentTexture; } } diff --git a/src/rshapes.c b/src/rshapes.c index 66dfbf3b606a..7c8658d1e5f4 100644 --- a/src/rshapes.c +++ b/src/rshapes.c @@ -718,10 +718,10 @@ void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color bottomRight.y = y + (dx + rec.width)*sinRotation + (dy + rec.height)*cosRotation; } -#if defined(SUPPORT_QUADS_DRAW_MODE) rlSetTexture(GetShapesTexture().id); Rectangle shapeRect = GetShapesTextureRectangle(); +#if defined(SUPPORT_QUADS_DRAW_MODE) rlBegin(RL_QUADS); rlNormal3f(0.0f, 0.0f, 1.0f); @@ -740,23 +740,34 @@ void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color rlVertex2f(topRight.x, topRight.y); rlEnd(); - - rlSetTexture(0); #else rlBegin(RL_TRIANGLES); + rlNormal3f(0.0f, 0.0f, 1.0f); rlColor4ub(color.r, color.g, color.b, color.a); + rlTexCoord2f(shapeRect.x/texShapes.width, shapeRect.y/texShapes.height); rlVertex2f(topLeft.x, topLeft.y); + + rlTexCoord2f(shapeRect.x/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); rlVertex2f(bottomLeft.x, bottomLeft.y); + + rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, shapeRect.y/texShapes.height); rlVertex2f(topRight.x, topRight.y); + rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, shapeRect.y/texShapes.height); rlVertex2f(topRight.x, topRight.y); + + rlTexCoord2f(shapeRect.x/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); rlVertex2f(bottomLeft.x, bottomLeft.y); + + rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); rlVertex2f(bottomRight.x, bottomRight.y); rlEnd(); #endif + + rlSetTexture(0); } // Draw a vertical-gradient-filled rectangle diff --git a/src/rtextures.c b/src/rtextures.c index 867add38e3c9..25e07af6d405 100644 --- a/src/rtextures.c +++ b/src/rtextures.c @@ -4604,6 +4604,7 @@ void DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2 } rlSetTexture(texture.id); +#if defined(SUPPORT_QUADS_DRAW_MODE) rlBegin(RL_QUADS); rlColor4ub(tint.r, tint.g, tint.b, tint.a); @@ -4630,7 +4631,6 @@ void DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2 rlVertex2f(topRight.x, topRight.y); rlEnd(); - rlSetTexture(0); // NOTE: Vertex position can be transformed using matrices // but the process is way more costly than just calculating @@ -4638,7 +4638,6 @@ void DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2 // I leave here the old implementation for educational purposes, // just in case someone wants to do some performance test /* - rlSetTexture(texture.id); rlPushMatrix(); rlTranslatef(dest.x, dest.y, 0.0f); if (rotation != 0.0f) rlRotatef(rotation, 0.0f, 0.0f, 1.0f); @@ -4669,8 +4668,47 @@ void DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2 rlVertex2f(dest.width, 0.0f); rlEnd(); rlPopMatrix(); - rlSetTexture(0); */ + +#else + rlBegin(RL_TRIANGLES); + + rlColor4ub(tint.r, tint.g, tint.b, tint.a); + rlNormal3f(0.0f, 0.0f, 1.0f); // Normal vector pointing towards viewer + + // Top-left corner for texture + if (flipX) rlTexCoord2f((source.x + source.width)/width, source.y/height); + else rlTexCoord2f(source.x/width, source.y/height); + rlVertex2f(topLeft.x, topLeft.y); + + // Bottom-left corner for texture + if (flipX) rlTexCoord2f((source.x + source.width)/width, (source.y + source.height)/height); + else rlTexCoord2f(source.x/width, (source.y + source.height)/height); + rlVertex2f(bottomLeft.x, bottomLeft.y); + + // Bottom-right corner for texture + if (flipX) rlTexCoord2f(source.x/width, (source.y + source.height)/height); + else rlTexCoord2f((source.x + source.width)/width, (source.y + source.height)/height); + rlVertex2f(bottomRight.x, bottomRight.y); + + // Top-left corner for texture + if (flipX) rlTexCoord2f((source.x + source.width)/width, source.y/height); + else rlTexCoord2f(source.x/width, source.y/height); + rlVertex2f(topLeft.x, topLeft.y); + + // Bottom-right corner for texture + if (flipX) rlTexCoord2f(source.x/width, (source.y + source.height)/height); + else rlTexCoord2f((source.x + source.width)/width, (source.y + source.height)/height); + rlVertex2f(bottomRight.x, bottomRight.y); + + // Top-right corner for texture + if (flipX) rlTexCoord2f(source.x/width, source.y/height); + else rlTexCoord2f((source.x + source.width)/width, source.y/height); + rlVertex2f(topRight.x, topRight.y); + + rlEnd(); +#endif + rlSetTexture(0); } }