diff options
| author | Ray <[email protected]> | 2019-01-10 16:57:15 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-01-10 16:57:15 +0100 |
| commit | 56173d7cf457413fd56e26967becc7c5054aa2cf (patch) | |
| tree | f1428e583f4ed5ee8c7060c47da55e8ce0194882 /src/textures.c | |
| parent | 6056a2a5cf2aa939a10e807e452ed43d4b67f1ce (diff) | |
| parent | 93471b0a7c75fc675f27fc74dfda281eb8310a7a (diff) | |
| download | raylib-56173d7cf457413fd56e26967becc7c5054aa2cf.tar.gz raylib-56173d7cf457413fd56e26967becc7c5054aa2cf.zip | |
Merge branch 'master' into window-visibility
Diffstat (limited to 'src/textures.c')
| -rw-r--r-- | src/textures.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/textures.c b/src/textures.c index fa1d7f0e..726a2a84 100644 --- a/src/textures.c +++ b/src/textures.c @@ -2418,6 +2418,17 @@ void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Co DrawTexturePro(texture, sourceRec, destRec, origin, 0.0f, tint); } +// Draw texture quad with tiling and offset parameters +// NOTE: Tiling and offset should be provided considering normalized texture values [0..1] +// i.e tiling = { 1.0f, 1.0f } refers to all texture, offset = { 0.5f, 0.5f } moves texture origin to center +void DrawTextureQuad(Texture2D texture, Vector2 tiling, Vector2 offset, Rectangle quad, Color tint) +{ + Rectangle source = { offset.x*texture.width, offset.y*texture.height, tiling.x*texture.width, tiling.y*texture.height }; + Vector2 origin = { 0.0f, 0.0f }; + + DrawTexturePro(texture, source, quad, origin, 0.0f, tint); +} + // Draw a part of a texture (defined by a rectangle) with 'pro' parameters // NOTE: origin is relative to destination rectangle size void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, float rotation, Color tint) @@ -2434,9 +2445,9 @@ void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, V rlEnableTexture(texture.id); rlPushMatrix(); - rlTranslatef(destRec.x, destRec.y, 0); - rlRotatef(rotation, 0, 0, 1); - rlTranslatef(-origin.x, -origin.y, 0); + rlTranslatef(destRec.x, destRec.y, 0.0f); + rlRotatef(rotation, 0.0f, 0.0f, 1.0f); + rlTranslatef(-origin.x, -origin.y, 0.0f); rlBegin(RL_QUADS); rlColor4ub(tint.r, tint.g, tint.b, tint.a); @@ -2464,6 +2475,7 @@ void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, V } } +// Draws a texture (or part of it) that stretches or shrinks nicely using n-patch info void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle destRec, Vector2 origin, float rotation, Color tint) { if (texture.id > 0) @@ -2524,9 +2536,9 @@ void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle destR rlEnableTexture(texture.id); rlPushMatrix(); - rlTranslatef(destRec.x, destRec.y, 0); - rlRotatef(rotation, 0, 0, 1); - rlTranslatef(-origin.x, -origin.y, 0); + rlTranslatef(destRec.x, destRec.y, 0.0f); + rlRotatef(rotation, 0.0f, 0.0f, 1.0f); + rlTranslatef(-origin.x, -origin.y, 0.0f); rlBegin(RL_QUADS); rlColor4ub(tint.r, tint.g, tint.b, tint.a); |
