Thread Tools Display Modes
04-25-13, 10:20 PM   #1
Ledii
A Deviate Faerie Dragon
 
Ledii's Avatar
Join Date: Apr 2013
Posts: 10
Exclamation Need help with SetTexture()

Hey, so I'm trying to learn about how the frames work. So I want to get a image up on the screen.
I have already created a main frame where i put all the other frames of my addon so that I can hide and show all at the same time easily.

The problem I'm having is that there is not very many good tutorials on how to do this and any ways to find out what properties and methods all different objects have. And When I try to load the image I keep getting a green square!

I have this file setup:
AddOns(folder)
> MyAddon(folder)
> > code.toc(file)
> > code.lua(file)
> > Textures(folder)
> > > test.tga(file)

And my code to get the image showing on the screen is like this...
MakeFrame() is a function I made that just assigns the parameters into the wanted frame and returns the result. (Don't worry about this, it works as intended)

local newTex = MakeFrame("ScrollFrame", "FW_Icon", {100, 100}, {100, -150}, mainFrame, nil, nil)
local tex = newTex:CreateTexture(newTex:GetName() .. "_Image", mainFrame)
tex:SetAllPoints()
tex:SetTexture("Interface\\AddOns\\FrameWork\\Textures\\test.tga")
print(prefix .. "Loaded " .. '"' .. tex:GetTexture() .. '"')

I did a google search on "wow lua settexture green" and tried everything i found. No use though.
__________________
Take it as it comes...
  Reply With Quote
04-25-13, 11:31 PM   #2
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
If the path to the image is correct, it will still fail if the image's dimensions are not a power of 2, or if it's not an actual blp or tga file.

I can't tell if your addon is called FrameWork (like it is in the path) or MyAddon like you described in your post, make sure your path is right.

edit: What I mean by powers of 2 is the width and height have to be something like 32, 64, 128, 256, 512.

Last edited by semlar : 04-25-13 at 11:34 PM.
  Reply With Quote
04-26-13, 07:12 PM   #3
Ledii
A Deviate Faerie Dragon
 
Ledii's Avatar
Join Date: Apr 2013
Posts: 10
Originally Posted by semlar View Post
If the path to the image is correct, it will still fail if the image's dimensions are not a power of 2, or if it's not an actual blp or tga file.

I can't tell if your addon is called FrameWork (like it is in the path) or MyAddon like you described in your post, make sure your path is right.

edit: What I mean by powers of 2 is the width and height have to be something like 32, 64, 128, 256, 512.
The image is 100x100, probably why then... That sounds like a very stupid rule in order to make images work. There are probably reasons it is like that, but it's ok. I can probably try resize it. Stupid stupid though -_-
__________________
Take it as it comes...
  Reply With Quote
04-26-13, 12:26 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If anything you described is working in-game, then the file paths and names you posted are fake -- your listed TOC file name "code.toc" does not match your listed folder name "MyAddon", so WoW cannot possibly be loading that file as an addon. Posting fake file paths, fake file names, or fake code is worse than posting nothing at all, because people who are trying to help you assume you're posting real stuff, and everyone's time gets wasted. >_<

Originally Posted by Ledii View Post
local tex = newTex:CreateTexture(newTex:GetName() .. "_Image", mainFrame)
Not related to your question, but you don't need to waste CPU time calling :GetName() -- you can just do "$parent_Image" and the "$parent" token will automatically be replaced by the name of the frame you are creating the texture on. This also works for font strings, animation groups, and animations.

Also, the second parameter to CreateTexture should be the layer on which the texture is drawn. I don't know what value your mainFrame variable contains, but if it's not a string naming a valid draw layer, it will (at best) result in your texture being on the wrong layer or maybe even (at worst) break your texture.

Finally, I know you said your MakeFrame function is working, and using a "factory" function like that is fine, but please for the love of kittens (or whatever cute things you have a soft spot for), don't waste memory creating and discarding tables like that. Just pass the values in sequence, or pass nil to skip a value.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
04-26-13, 04:09 AM   #5
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Code:
function TextureBasics_CreateTexture(texture)
	-- Create a frame
	local f = CreateFrame("frame", "TextureBasics")
	-- Frame Strata ("Background", "Low", "Medium", "High", "Dialog", "Fullscreen", "Fullscreen_Dialog", "Tooltip")
	f:SetFrameStrata("Medium")
	-- Frame Strata level (0 - 20)
	f:SetFrameLevel(0)
	-- Frame Width
	f:SetWidth(128)
	-- Frame Height
	f:SetHeight(128)
	-- Frame Alpha
	f:SetAlpha(0.90)
	-- Frame Position
	f:SetPoint("CENTER", 0, 0);
	-- Create a texture on the frame
	local t = f:CreateTexture("Texture", "Background")
	-- Set the texture
	t:SetTexture(texture)
	-- Texture Width
	t:SetWidth(128)
	-- Texture Height
	t:SetHeight(128)
	-- Blend Mode ("Add", "Alphakey", "Blend", "Disable", "Mod")
	t:SetBlendMode("Disable")
	-- Texture Strata ("Background", "Border", "Artwork", "Overlay") and Sublevel (-8 - 7)
	t:SetDrawLayer("Background", 0)
	-- Texture Rotation (0 - 360) (Note, not all textures like to be rotated)
	t:SetRotation(math.rad(15))
	-- Coloring (r, b, g, a)
	t:SetVertexColor(1, 0, 0, 0.75)
	-- If you rotate it you need multiply the frame's width and height by sqrt(2)
	f:SetWidth(sqrt(2) * t:GetWidth())
	f:SetHeight(sqrt(2) * t:GetHeight())
	-- Mirror it
	local ULx, ULy, LLx, LLy, URx, URy, LRx, LRy = t:GetTexCoord();
	--t:SetTexCoord(URx, URy, LRx, LRy, ULx, ULy, LLx, LLy); -- Inverse X
	--t:SetTexCoord(LLx, LLy, ULx, ULy, LRx, LRy, URx, URy); -- Inverse Y
	--t:SetTexCoord(LRx, LRy, URx, URy, LLx, LLy, ULx, ULy); -- Inverse XY
	t:SetTexCoord(ULx, ULy, LLx, LLy, URx, URy, LRx, LRy); -- Normal
	-- Put the texture on the frame
	t:SetAllPoints(f)
	-- Show it
	f:Show()
end

TextureBasics_CreateTexture("Interface\\PVPFrame\\Icons\\PVP-Banner-Emblem-10")
You can draw more texture ingame with command:

Code:
/run TextureBasics_CreateTexture(texture)
If you rotate icons from the game you gonna get a glitch:

Code:
/run TextureBasics_CreateTexture("Interface\\Icons\\Ability_Ambush")
https://github.com/Resike/TextureBasics

Last edited by Resike : 04-26-13 at 04:33 AM.
  Reply With Quote
04-26-13, 09:29 AM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,334
Another possibility that wasn't explained here, did you close the game client completely and restart it? If you create or move files around in the WoW folders while the game is running, it will not be able to pick up the new files until it's been restarted.

The texture turning green is an indicator that there's something wrong with the image file, either it's encoded wrong, dimensions are invalid, or the file could not be found or didn't exist at the time the game client started.

WoW is very picky about its textures. The image needs to be encoded as a 32-bit TGA (TGA with alpha layer). Most image editors only encode 24-bit TGAs. The dimensions are required to be a power of 2 between 8 and 512 inclusive. These do not need to be the same, for example, you can have a 256x128 sized texture image.





On another note:
Originally Posted by Resike View Post
Code:
local ULx, ULy, LLx, LLy, URx, URy, LRx, LRy = t:GetTexCoord();
t:SetTexCoord(ULx, ULy, LLx, LLy, URx, URy, LRx, LRy);-- Normal
I seriously hope you're not really doing this.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 04-26-13 at 09:55 AM.
  Reply With Quote
04-26-13, 11:12 AM   #7
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by SDPhantom View Post
Another possibility that wasn't explained here, did you close the game client completely and restart it? If you create or move files around in the WoW folders while the game is running, it will not be able to pick up the new files until it's been restarted.

The texture turning green is an indicator that there's something wrong with the image file, either it's encoded wrong, dimensions are invalid, or the file could not be found or didn't exist at the time the game client started.

WoW is very picky about its textures. The image needs to be encoded as a 32-bit TGA (TGA with alpha layer). Most image editors only encode 24-bit TGAs. The dimensions are required to be a power of 2 between 8 and 512 inclusive. These do not need to be the same, for example, you can have a 256x128 sized texture image.





On another note:

I seriously hope you're not really doing this.
Well i just ctrl+c-d it from my addon, it's just a showcase tho. :P
  Reply With Quote
04-26-13, 07:14 PM   #8
Ledii
A Deviate Faerie Dragon
 
Ledii's Avatar
Join Date: Apr 2013
Posts: 10
Originally Posted by Resike View Post
Well i just ctrl+c-d it from my addon, it's just a showcase tho. :P
Yes, I did read up on that, and found out about the restarting.
The requirement of having to have a dimension of power 2 is the dumbest property I have ever heard though. How am we supposed to find that out easily -_-
__________________
Take it as it comes...
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Need help with SetTexture()


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