From e9143b8a8d2eb439b01b94c00518db2b59ffb1e7 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Thu, 28 Nov 2013 19:59:56 +0100 Subject: Added some functions and Updated examples View CHANGELOG for details --- src/textures.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'src/textures.c') 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) -- cgit v1.2.3