Page 1 of 2

Calculate the size of a texture

Posted: 02 Nov 2009, 14:10
by Tribulex
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

Posted: 02 Nov 2009, 16:39
by jK
check the wiki ...

Re: Calculate the size of a texture

Posted: 02 Nov 2009, 16:42
by Tribulex
jK wrote:check the wiki ...
I did. Once again i failed to see the light.

Re: Calculate the size of a texture

Posted: 02 Nov 2009, 16:43
by Tribulex
Omg, lock/delete this....

http://quotes.springlobby.info/?69

Re: Calculate the size of a texture

Posted: 02 Nov 2009, 18:12
by Tribulex
NO WAIT it doesnt working!

Code: Select all

gl.TextureInfo

 ( string texture ) -> nil | {
     xsize = number,
     ysize = number,
     alpha = boolean, //not used yet
     type  = number,  //not used yet
   }
so i am trying to do this:

Code: Select all

    local texinfo = glTextureInfo(file)
    if texinfo then Spring.Echo(#texinfo) end
    local sizex = texinfo['xsize']
    local sizey = texinfo['ysize']
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

Posted: 02 Nov 2009, 18:59
by SirMaverick
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)
The function returns nil, that's why it doesn't print anything and you get that error (trying to index nil value).

Re: Calculate the size of a texture

Posted: 02 Nov 2009, 19:04
by Tribulex
SirMaverick wrote:
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)
The function returns nil, that's why it doesn't print anything and you get that error (trying to index nil value).
Then how in the world do i use this function?

Re: Calculate the size of a texture

Posted: 02 Nov 2009, 19:47
by FLOZi
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

Posted: 02 Nov 2009, 19:50
by Tribulex
FLOZi wrote:Assuming the function is being called correctly, it means something is wrong with what you're giving it
What is wrong?

Re: Calculate the size of a texture

Posted: 02 Nov 2009, 20:03
by SirMaverick
d_b wrote:
FLOZi wrote:Assuming the function is being called correctly, it means something is wrong with what you're giving it
What is wrong?
Assuming the function is being called correctly, it means something is wrong with provided argument.

Re: Calculate the size of a texture

Posted: 02 Nov 2009, 20:09
by AF
What I am seeing:
  • 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
This is ignorant and attrocious, and it puts off new developers forum lurking from asking questions.

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.

Re: Calculate the size of a texture

Posted: 02 Nov 2009, 20:12
by Tribulex
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.

Re: Calculate the size of a texture

Posted: 02 Nov 2009, 20:48
by zwzsg
That only happens because you asks the wrong questions! :wink:

Re: Calculate the size of a texture

Posted: 02 Nov 2009, 21:44
by Forboding Angel
AF wrote:What I am seeing:
  • 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
This is ignorant and attrocious, and it puts off new developers forum lurking from asking questions.

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.
+9001!!!!!

Re: Calculate the size of a texture

Posted: 02 Nov 2009, 21:47
by SirMaverick
The original question was answered in the 2nd post.

For the given example, help was provided as far as info was given.

Re: Calculate the size of a texture

Posted: 02 Nov 2009, 21:50
by Forboding Angel
d_b wrote:
SirMaverick wrote:
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)
The function returns nil, that's why it doesn't print anything and you get that error (trying to index nil value).
Then how in the world do i use this function?
Mav,

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".

Re: Calculate the size of a texture

Posted: 02 Nov 2009, 22:06
by SirMaverick
"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?

Re: Calculate the size of a texture

Posted: 02 Nov 2009, 22:37
by CarRepairer
d_b wrote:NO WAIT it doesnt working!

Code: Select all

gl.TextureInfo

 ( string texture ) -> nil | {
     xsize = number,
     ysize = number,
     alpha = boolean, //not used yet
     type  = number,  //not used yet
   }
so i am trying to do this:

Code: Select all

    local texinfo = glTextureInfo(file)
    if texinfo then Spring.Echo(#texinfo) end
    local sizex = texinfo['xsize']
    local sizey = texinfo['ysize']
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)
Okay everyone settle down.

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

Posted: 02 Nov 2009, 22:56
by jK
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.
wiki says in a note:
the format of the texture string is the same as in gl.Texture()

Re: Calculate the size of a texture

Posted: 02 Nov 2009, 22:58
by Argh
So, therefore, the answer would be...

Code: Select all

local sizex, sizey = gl.TextureInfo(gl.Texture(file))