Thread Tools Display Modes
01-19-14, 09:42 AM   #1
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Help with SetTexCoord()

Today I'm asking you for some help with SetTexCoord().
I'm trying to transform icon textures into a 'trapezoid' form. Unfortunately the results are somewhat unexpected.

Let's consider the following code:

Lua Code:
  1. tFrame = CreateFrame("Frame", UIParent)
  2. tFrame:SetPoint("CENTER", UIParent, "CENTER")
  3. tFrame:SetHeight(100)
  4. tFrame:SetWidth(100)
  5. tFrame:Show()
  6.        
  7. tTex = tFrame:CreateTexture(nil,"OVERLAY")
  8. tTex:SetTexture("Interface\\icons\\ability_ambush")
  9. tTex:SetPoint("CENTER", tFrame, "CENTER")
  10. tTex:SetTexCoord(0,0, -0.25,1, 1,0, 1.25, 1)
  11. tTex:Show()

For your overview:
Texture coordinates are
ULx/y: 0/0 URx/y: 1/0
LLx/y: 0/1 LRx/y: 1/1
And the SetTexCoord parameters are ULx/y, LLx/y, URx/y, LRx/y

The result of the code above should be like the one on the right side (I've made this one with Photoshop ... just to show what I'm expecting) in this image:



But the result is like the left one. Almost like expected ... but somewhat 'distorted' in the lower left corner. :/

I can't see where this 'distortion' comes from. Does anyone has an idea?

btw: If you test my code above the actual result will be like this:

This is as expected and is not related to my problem. I've replace the icon texture by a copy of it with a single transparent pixel at all borders. That's all.

Edit
Tried it with a more 'specific' texture. The left one is original, the right one is transformed. Weird.

Last edited by Duugu : 01-19-14 at 10:01 AM.
  Reply With Quote
01-19-14, 11:54 AM   #2
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
God that red grid on that green background just killed my eyes. Anyway i also played around with this, and ended up with it's cant be done properly.



As you can see whitin my awesome photoshop skills i think blizazrds settexcord function can't handle properly when you edit all the 4 corner's coordinates. Most likely because it's doesn't start the torsion from the image's center, but it's topleft and bottomright coords.

Last edited by Resike : 01-19-14 at 12:00 PM.
  Reply With Quote
01-19-14, 04:12 PM   #3
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Not that it eliminates the distortion, but you can get a result closer to your example by fiddling with the numbers and changing the height..
Lua Code:
  1. local tx = UIParent:CreateTexture(nil, 'BACKGROUND')
  2. tx:SetSize(80, 80)
  3. tx:SetPoint('CENTER')
  4. tx:SetTexture(0,0.8,0.2,0.5)
  5.  
  6. local icon = UIParent:CreateTexture(nil, 'OVERLAY')
  7. icon:SetTexture('interface/icons/ability_ambush', true)
  8. icon:SetPoint('CENTER', tx)
  9. icon:SetSize(80, 120)
  10. icon:SetTexCoord(0, -0.25, -0.25, 1.25, 1, -0.25, 1.25, 1.25)
  Reply With Quote
01-20-14, 12:32 AM   #4
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Thank you semlar. I've actually never heard of or used region:SetSize(). oO
That definitely helps a lot.

Today I came up with a complete different way to show undistorted textures of this shape. But be warned .... it's kind of a bad hack. If you are of a sensitive mind then you shouldn't read further.

Nevertheless ... here it is:
Lua Code:
  1. tFrame = CreateFrame("Frame", UIParent)
  2. tFrame:SetPoint("CENTER", UIParent, "CENTER")
  3. tFrame:SetHeight(200)
  4. tFrame:SetWidth(200)
  5. tFrame:Show()
  6. tTex = tFrame:CreateTexture("t0","OVERLAY")
  7. tTex:SetTexture("Interface\\icons\\ability_ambush")
  8. tTex:SetHeight(1)
  9. tTex:SetWidth(tFrame:GetWidth())
  10. tTex:SetPoint("TOP", tFrame, "TOP", 0, 0)
  11. tTex:SetTexCoord(0, 1, 0, 1 / tFrame:GetHeight())
  12. tTex:Show()    
  13. for x = 1, tFrame:GetHeight() do
  14.         tTex = tFrame:CreateTexture("t"..x,"OVERLAY")
  15.         tTex:SetTexture("Interface\\icons\\ability_ambush")
  16.         tTex:SetHeight(1)
  17.         tTex:SetWidth(tFrame:GetWidth())
  18.         tTex:SetPoint("TOP", _G["t"..(x - 1)], "BOTTOM")
  19.         tTex:SetTexCoord(-((1 / tFrame:GetHeight()) * x), 1 + (1 / tFrame:GetHeight()) * x, (1 / tFrame:GetHeight()) * x, ((1 / tFrame:GetHeight()) * x) + (1 / tFrame:GetHeight()))
  20.         tTex:Show()    
  21. end

It just comprises the full texture of a lot of single line textures. Should be easy to write a SetTexture wrapper function to set and handle those 'textures'.

Unfortunately it raises new problems. I'm rotating the parent frame of the textures, and as we know the animation thingi is a great mess. It can't handle textures that are not anchored to the center of the parent widget.

And yes, I know, creating 200 textures to show a single one is a big waste of ressources.

Last edited by Duugu : 01-20-14 at 12:41 AM.
  Reply With Quote
01-20-14, 11:24 AM   #5
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
You should check this thread:

http://www.wowinterface.com/forums/s...t=36679&page=2
  Reply With Quote
01-21-14, 12:42 AM   #6
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Originally Posted by Resike View Post
Thank you. But ... hm ... it's about rotating textures. I'm a bit lost. :/ Could you please be more specific? Which part of it?

Last edited by Duugu : 01-21-14 at 12:45 AM.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Help with SetTexCoord()


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off