Calculate the size of a texture
Moderator: Moderators
Calculate the size of a texture
How do I use lua to calculate the size in pixels of a texture i load with gl.texture?
Re: Calculate the size of a texture
check the wiki ...
Re: Calculate the size of a texture
I did. Once again i failed to see the light.jK wrote:check the wiki ...
Re: Calculate the size of a texture
NO WAIT it doesnt working!
so i am trying to do this:
Its not printing anything, and its giving this error:
Code: Select all
gl.TextureInfo
( string texture ) -> nil | {
xsize = number,
ysize = number,
alpha = boolean, //not used yet
type = number, //not used yet
}
Code: Select all
local texinfo = glTextureInfo(file)
if texinfo then Spring.Echo(#texinfo) end
local sizex = texinfo['xsize']
local sizey = texinfo['ysize']
Code: Select all
[ 0] LuaRules::RunCallIn: error = 2, DrawScreen, [string "LuaRules/Gadgets/gui_gewy.lua"]:30: attempt to index local 'texinfo' (a nil value)
-
- Posts: 834
- Joined: 19 May 2009, 21:10
Re: Calculate the size of a texture
The function returns nil, that's why it doesn't print anything and you get that error (trying to index nil value).d_b wrote:Its not printing anything, and its giving this error:
Code: Select all
[ 0] LuaRules::RunCallIn: error = 2, DrawScreen, [string "LuaRules/Gadgets/gui_gewy.lua"]:30: attempt to index local 'texinfo' (a nil value)
Re: Calculate the size of a texture
Then how in the world do i use this function?SirMaverick wrote:The function returns nil, that's why it doesn't print anything and you get that error (trying to index nil value).d_b wrote:Its not printing anything, and its giving this error:
Code: Select all
[ 0] LuaRules::RunCallIn: error = 2, DrawScreen, [string "LuaRules/Gadgets/gui_gewy.lua"]:30: attempt to index local 'texinfo' (a nil value)
Re: Calculate the size of a texture
Assuming the function is being called correctly, it means something is wrong with what you're giving it
Re: Calculate the size of a texture
What is wrong?FLOZi wrote:Assuming the function is being called correctly, it means something is wrong with what you're giving it
-
- Posts: 834
- Joined: 19 May 2009, 21:10
Re: Calculate the size of a texture
Assuming the function is being called correctly, it means something is wrong with provided argument.d_b wrote:What is wrong?FLOZi wrote:Assuming the function is being called correctly, it means something is wrong with what you're giving it
Re: Calculate the size of a texture
What I am seeing:
An example being where he wanted to know the vertices of a model and it was thrown back in his face as people assumed he wanted to draw a wireframe.
Even when he repeated that this was not true, people still flamed him for being stupid and not rendering the wireframe the way they suggested, even though he didnt want a wireframe in the first place!!!!
It took argh of all people to waltz in and blow his trumpet before anybody gave a remotely plausible answer.
- person asks how to do A
- it is assumed that person is trying to use A as a means to B
- No answer is given for A and instead a dismissal followed by an answer for B is given
- Original poster responds that this is not what he asked for
- This is dismissed and a 'rtfm' is given
An example being where he wanted to know the vertices of a model and it was thrown back in his face as people assumed he wanted to draw a wireframe.
Even when he repeated that this was not true, people still flamed him for being stupid and not rendering the wireframe the way they suggested, even though he didnt want a wireframe in the first place!!!!
It took argh of all people to waltz in and blow his trumpet before anybody gave a remotely plausible answer.
Last edited by AF on 02 Nov 2009, 20:13, edited 1 time in total.
Re: Calculate the size of a texture
While a very truthful post, yet again it does not pertain to the topic :)
However, you are forgiven for pointing out a very serious truth about this forum. You will get answers immediately, but they don't answer the the question you asked.
However, you are forgiven for pointing out a very serious truth about this forum. You will get answers immediately, but they don't answer the the question you asked.
Re: Calculate the size of a texture
That only happens because you asks the wrong questions! 

- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Calculate the size of a texture
+9001!!!!!AF wrote:What I am seeing:
This is ignorant and attrocious, and it puts off new developers forum lurking from asking questions.
- person asks how to do A
- it is assumed that person is trying to use A as a means to B
- No answer is given for A and instead a dismissal followed by an answer for B is given
- Original poster responds that this is not what he asked for
- This is dismissed and a 'rtfm' is given
An example being where he wanted to know the vertices of a model and it was thrown back in his face as people assumed he wanted to draw a wireframe.
Even when he repeated that this was not true, people still flamed him for being stupid and not rendering the wireframe the way they suggested, even though he didnt want a wireframe in the first place!!!!
It took argh of all people to waltz in and blow his trumpet before anybody gave a remotely plausible answer.
-
- Posts: 834
- Joined: 19 May 2009, 21:10
Re: Calculate the size of a texture
The original question was answered in the 2nd post.
For the given example, help was provided as far as info was given.
For the given example, help was provided as far as info was given.
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Calculate the size of a texture
Mav,d_b wrote:Then how in the world do i use this function?SirMaverick wrote:The function returns nil, that's why it doesn't print anything and you get that error (trying to index nil value).d_b wrote:Its not printing anything, and its giving this error:
Code: Select all
[ 0] LuaRules::RunCallIn: error = 2, DrawScreen, [string "LuaRules/Gadgets/gui_gewy.lua"]:30: attempt to index local 'texinfo' (a nil value)
readplskthx
He posted how he was trying to use the function, apparently he's doin ir rong, but if you took the time to look at his code, it stands to reason you could correct his usage, yes?
I swear to christ, I'm going to go on a crusade to rid the lua forum of all these bullshit "answers".
-
- Posts: 834
- Joined: 19 May 2009, 21:10
Re: Calculate the size of a texture
"For the given example, help was provided as far as info was given."
The only person to solve this is he himself. Only he knows what argument he is using for this function. How can anybody else help if no one else knows about the context?
The only person to solve this is he himself. Only he knows what argument he is using for this function. How can anybody else help if no one else knows about the context?
- CarRepairer
- Cursed Zero-K Developer
- Posts: 3359
- Joined: 07 Nov 2007, 21:48
Re: Calculate the size of a texture
Okay everyone settle down.d_b wrote:NO WAIT it doesnt working!
so i am trying to do this:Code: Select all
gl.TextureInfo ( string texture ) -> nil | { xsize = number, ysize = number, alpha = boolean, //not used yet type = number, //not used yet }
Its not printing anything, and its giving this error:Code: Select all
local texinfo = glTextureInfo(file) if texinfo then Spring.Echo(#texinfo) end local sizex = texinfo['xsize'] local sizey = texinfo['ysize']
Code: Select all
[ 0] LuaRules::RunCallIn: error = 2, DrawScreen, [string "LuaRules/Gadgets/gui_gewy.lua"]:30: attempt to index local 'texinfo' (a nil value)
I'm going to go out on a limb here... and assume that the variable he passed to the function - file - is a filename. You need to pass it a texture string, such as one returned by gl.CreateTexture.
Re: Calculate the size of a texture
wiki says in a note:CarRepairer wrote:I'm going to go out on a limb here... and assume that the variable he passed to the function - file - is a filename. You need to pass it a texture string, such as one returned by gl.CreateTexture.
the format of the texture string is the same as in gl.Texture()
Re: Calculate the size of a texture
So, therefore, the answer would be...
Code: Select all
local sizex, sizey = gl.TextureInfo(gl.Texture(file))