View Single Post
03-31-16, 02:10 PM   #12
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
You don't have to do that. You can just use the native texture resolution that you have and then choose the power of 2 above that if it doesn't fit. Use Texture:SetTexCoord(...) to crop the texture in-game instead. If you haven't noticed, a lot of Blizzard textures are comprised of multiple small textures mashed together in one big file. They then use texture coordinates to crop out individual parts.

Calculating the fractions on texture coordinates is a fairly simple formula:

Texture:SetTexCoord(left, right, top, bottom)
  • left - Left (or minX) edge of the scaled/cropped image, as a fraction of the image's width from the left (number)
  • right - Right (or maxX) edge of the scaled/cropped image, as a fraction of the image's width from the left (number)
  • top - Top (or minY) edge of the scaled/cropped image, as a fraction of the image's height from the top (number)
  • bottom - Bottom (or maxY) edge of the scaled/cropped image, as a fraction of the image's height from the top (number)
Lua Code:
  1. Texture:SetTexCoord(pxLeftFromLeftEdge / texWidth, pxRightFromLeftEdge / texWidth, pxTopFromTopEdge / texHeight, pxBottomFromTopEdge / texheight)

As an example, you can do this:
Lua Code:
  1. -- Default
  2. Texture:SetTexCoord(0, 1, 0, 1)
  3.  
  4. -- Horizontal flip
  5. Texture:SetTexCoord(1, 0, 0, 1)
  6.  
  7. -- Vertical flip
  8. Texture:SetTexCoord(0, 1, 1, 0)
  9.  
  10. -- Crop 25% from the left side
  11. Texture:SetTexCoord(0.25, 1, 0, 1)
  12.  
  13. -- Crop 25% from the right side
  14. Texture:SetTexCoord(0, 0.75, 0, 1)

Here's how you can use photoshop's reference point (the 9-piece grid) to find the coordinates with relative ease:


There's also a longer version of Texture:SetTexCoord(...) that allows you to specify all four corners of the texture. You can think of that approach as holding up a towel and grabbing at different points on it to let the unwanted part fold away, but that's not necessary if you're not cropping + rotating at the same time.
__________________

Last edited by MunkDev : 03-31-16 at 02:22 PM.
  Reply With Quote