Calculate the size of a texture
Posted: 02 Nov 2009, 14:10
How do I use lua to calculate the size in pixels of a texture i load with gl.texture?
Open Source Realtime Strategy Game Engine
https://springrts.licho.eu/phpbb/
I did. Once again i failed to see the light.jK wrote:check the wiki ...
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)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)
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)
What is wrong?FLOZi wrote:Assuming the function is being called correctly, it means something is wrong with what you're giving it
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
+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.
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)
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)
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()
Code: Select all
local sizex, sizey = gl.TextureInfo(gl.Texture(file))