aboutsummaryrefslogtreecommitdiff
path: root/src/textures.c
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2013-11-28 19:59:56 +0100
committerraysan5 <raysan5@gmail.com>2013-11-28 19:59:56 +0100
commite9143b8a8d2eb439b01b94c00518db2b59ffb1e7 (patch)
tree8539603494a773f852721da1d6f7b19bca0d8f64 /src/textures.c
parent818e79638b5ff14fdae9f6a162e596bf119f82c5 (diff)
downloadraylib-e9143b8a8d2eb439b01b94c00518db2b59ffb1e7.tar.gz
raylib-e9143b8a8d2eb439b01b94c00518db2b59ffb1e7.zip
Added some functions and Updated examples
View CHANGELOG for details
Diffstat (limited to 'src/textures.c')
-rw-r--r--src/textures.c42
1 files changed, 40 insertions, 2 deletions
diff --git a/src/textures.c b/src/textures.c
index fc342a80..3ccb5358 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -197,7 +197,7 @@ void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float sc
}
// Draw a part of a texture (defined by a rectangle)
-void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, float scale, Color tint)
+void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint)
{
glEnable(GL_TEXTURE_2D); // Enable textures usage
@@ -205,7 +205,7 @@ void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, fl
glPushMatrix();
glTranslatef(position.x, position.y, 0);
- glScalef(scale, scale, 1.0f);
+ //glScalef(1.0f, 1.0f, 1.0f);
//glRotatef(rotation, 0, 0, 1);
glBegin(GL_QUADS);
@@ -233,6 +233,44 @@ void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, fl
glDisable(GL_TEXTURE_2D); // Disable textures usage
}
+// Draw a part of a texture (defined by a rectangle) with 'pro' parameters
+// TODO: Test this function...
+void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, float rotation, Color tint)
+{
+ glEnable(GL_TEXTURE_2D); // Enable textures usage
+
+ glBindTexture(GL_TEXTURE_2D, texture.glId);
+
+ glPushMatrix();
+ glTranslatef(-origin.x, -origin.y, 0);
+ glRotatef(rotation, 0, 0, 1);
+ glTranslatef(destRec.x + origin.x, destRec.y + origin.y, 0);
+
+ glBegin(GL_QUADS);
+ glColor4ub(tint.r, tint.g, tint.b, tint.a);
+ glNormal3f(0.0f, 0.0f, 1.0f); // Normal vector pointing towards viewer
+
+ // Bottom-left corner for texture and quad
+ glTexCoord2f((float)sourceRec.x / texture.width, (float)sourceRec.y / texture.height);
+ glVertex2f(0.0f, 0.0f);
+
+ // Bottom-right corner for texture and quad
+ glTexCoord2f((float)(sourceRec.x + sourceRec.width) / texture.width, (float)sourceRec.y / texture.height);
+ glVertex2f(destRec.width, 0.0f);
+
+ // Top-right corner for texture and quad
+ glTexCoord2f((float)(sourceRec.x + sourceRec.width) / texture.width, (float)(sourceRec.y + sourceRec.height) / texture.height);
+ glVertex2f(destRec.width, destRec.height);
+
+ // Top-left corner for texture and quad
+ glTexCoord2f((float)sourceRec.x / texture.width, (float)(sourceRec.y + sourceRec.height) / texture.height);
+ glVertex2f(0.0f, destRec.height);
+ glEnd();
+ glPopMatrix();
+
+ glDisable(GL_TEXTURE_2D); // Disable textures usage
+}
+
// Creates a bitmap (BMP) file from an array of pixel data
// NOTE: This function is only used by module [core], not explicitly available to raylib users
extern void WriteBitmap(const char *fileName, const Color *imgDataPixel, int width, int height)