Calculate the size of a texture

Calculate the size of a texture

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

User avatar
Tribulex
A.N.T.S. Developer
Posts: 1894
Joined: 26 Sep 2009, 21:26

Calculate the size of a texture

Post by Tribulex »

How do I use lua to calculate the size in pixels of a texture i load with gl.texture?
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Calculate the size of a texture

Post by jK »

check the wiki ...
User avatar
Tribulex
A.N.T.S. Developer
Posts: 1894
Joined: 26 Sep 2009, 21:26

Re: Calculate the size of a texture

Post by Tribulex »

jK wrote:check the wiki ...
I did. Once again i failed to see the light.
User avatar
Tribulex
A.N.T.S. Developer
Posts: 1894
Joined: 26 Sep 2009, 21:26

Re: Calculate the size of a texture

Post by Tribulex »

Omg, lock/delete this....

http://quotes.springlobby.info/?69
User avatar
Tribulex
A.N.T.S. Developer
Posts: 1894
Joined: 26 Sep 2009, 21:26

Re: Calculate the size of a texture

Post 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)
SirMaverick
Posts: 834
Joined: 19 May 2009, 21:10

Re: Calculate the size of a texture

Post 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).
User avatar
Tribulex
A.N.T.S. Developer
Posts: 1894
Joined: 26 Sep 2009, 21:26

Re: Calculate the size of a texture

Post 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?
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: Calculate the size of a texture

Post by FLOZi »

Assuming the function is being called correctly, it means something is wrong with what you're giving it
User avatar
Tribulex
A.N.T.S. Developer
Posts: 1894
Joined: 26 Sep 2009, 21:26

Re: Calculate the size of a texture

Post 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?
SirMaverick
Posts: 834
Joined: 19 May 2009, 21:10

Re: Calculate the size of a texture

Post 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.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Calculate the size of a texture

Post 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.
Last edited by AF on 02 Nov 2009, 20:13, edited 1 time in total.
User avatar
Tribulex
A.N.T.S. Developer
Posts: 1894
Joined: 26 Sep 2009, 21:26

Re: Calculate the size of a texture

Post 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.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Calculate the size of a texture

Post by zwzsg »

That only happens because you asks the wrong questions! :wink:
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Calculate the size of a texture

Post 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!!!!!
SirMaverick
Posts: 834
Joined: 19 May 2009, 21:10

Re: Calculate the size of a texture

Post by SirMaverick »

The original question was answered in the 2nd post.

For the given example, help was provided as far as info was given.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Calculate the size of a texture

Post 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".
SirMaverick
Posts: 834
Joined: 19 May 2009, 21:10

Re: Calculate the size of a texture

Post 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?
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Calculate the size of a texture

Post 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.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Calculate the size of a texture

Post 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()
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Calculate the size of a texture

Post by Argh »

So, therefore, the answer would be...

Code: Select all

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

Return to “Lua Scripts”