Crop tga using SetTexCoord

Welp, I have a 800x440 image of Ragefire Chasm with notes on it. I stuck it in the upper left corner of a 1024x512 tga file. Now I’m trying to use SetTexCoord() to crop the image and only show the map, leaving out the white space. But when I try I get get no image. It only works if I show the full image with whitespace. I guess I don’t fully understand the function. Any help would be appreciated! (There are commented out lines of code as I try different solutions and they don’t work.)

local fgfww = CreateFrame(“Frame”,nil,UIParent)
fgfww:SetFrameStrata(“BACKGROUND”)
fgfww:SetWidth(1024) – Set these to whatever height/width is needed
fgfww:SetHeight(512) – for your Texture
fgfww:SetMovable(true)
fgfww:EnableMouse(true)
fgfww:SetScript(“OnMouseDown”,function()
fgfww:StartMoving()
end)
fgfww:SetScript(“OnMouseUp”,function()
fgfww:StopMovingOrSizing()
end)

– the key to cropping images in wow lua is settexcoord but i cant master it

local tgtww = fgfww:CreateTexture(nil,“BACKGROUND”)
tgtww:SetTexture(“Interface\AddOns\dummyrfc\rfc-base-map.tga”)
–tgtww:SetTexture:SetTexCoord(0, 0.5, 0, 0.5)
–tgtww:SetTexture:SetTexCoord(0, 800/1024, 0, 440/512)
tgtww:SetAllPoints(fgfww)
fgfww.texture = tgtww
–texture:SetPoint(“LEFT”, frame, -40, 0)
–texture:SetSize(40, 40)

fgfww:SetPoint(“CENTER”,0,0)
fgfww:Show()

local fgfww = CreateFrame("Frame", nil, UIParent)
fgfww:SetPoint("CENTER")
fgfww:SetFrameStrata("BACKGROUND")
fgfww:SetSize(1024, 512) 
fgfww:SetMovable(true)
fgfww:EnableMouse(true)
fgfww:SetScript("OnMouseDown",function()
    fgfww:StartMoving()
end)
fgfww:SetScript("OnMouseUp",function()
    fgfww:StopMovingOrSizing()
end)

– the key to cropping images in wow lua is settexcoord but i cant master it

fgfww.Map = fgfww:CreateTexture()
fgfww.Map:SetAllPoints()
fgfww.Map:SetTexture("Interface\\AddOns\\dummyrfc\\rfc-base-map") -- will test for .blp and .tga files
--fgfww.Map:SetTexCoord(0, 0.5, 0, 0.5)
fgfww.Map:SetTexCoord(0, 800/1024, 0, 440/512) -- crop the texture to coords

You can use a addon like Discord Art (or probably KgPanels) to see your map and set/test the coords dynamically to be copied top your addon rather than fiddling with the numbers and a thousand /reloads

I think the problem is i need to use GetTexture instead of SetTexture.

tgtww:GetTexture():SetTexCoord(0, 800/1024, 0, 440/512)

No, the coords adjust the image inside the texture widget like a viewport.

Maybe if I had the image I could be a bit more exact. Possibly the coords you are using are wrong which is why I suggested start with something like DART.

Two things jump out at me:

You probably want:

texture:SetTexCoord(0,800/1024,0,440/512)

rather than

texture:SetTexture:SetTexCoord(0,800/1024,0,440/512)

If this is the problem, I recommend turning on script errors:

/console scriptErrors 1

Also when you have backslashes in lua (it’s fine in XML) you need to escape them or make it a non-mutable string:

tgtww:SetTexture("Interface\\AddOns\\dummyrfc\\rfc-base-map.tga")

Gello had the fix with this:

texture:SetTexCoord(0,800/1024,0,440/512)

it now properly crops the image. Thanks Gello! You are amazing!