Page 1 of 1

Button image with LUA?

Posted: Wed Mar 08, 2006 00:31
by hkroger
Hi,

I wanted to change button image with LUA. This is the code so far:

Code: Select all

   local button = wmgr:createWindow("WindowsLook/Button","toolbartestbutton");
   button:setText( "Test" )
   button:setSize( CEGUI.Size:new_local(0.5,0.1) )
   button:setPosition( CEGUI.Point:new_local(0.0,0.8) )
   
   local imagesetman = CEGUI.ImagesetManager:getSingleton()
   local imageset = imagesetman:getImageset("Editor")
   local image = imageset:getImage("ToolbarIcon1")
   
   button:setProperty( "NormalImage", image );


As you might guess, it does not work as property gets always a string a parameter. How can I make this work?

I really would like to see more LUA+CEGUI source code online. Good documentation would not hurt either.

Posted: Wed Mar 08, 2006 15:40
by Trentin
Try this:

Code: Select all

local button = wmgr:createWindow("WindowsLook/Button","toolbartestbutton");
button:setText( "Test" )
button:setSize( CEGUI.Size:new_local(0.5,0.1) )
button:setPosition( CEGUI.Point:new_local(0.0,0.8) )

button:setProperty( "NormalImage", "set:Editor image:ToolbarIcon1");


Hope that works, haven't actually tried it :)

Posted: Wed Mar 08, 2006 21:00
by hkroger
Trentin wrote:Try this:

Code: Select all

local button = wmgr:createWindow("WindowsLook/Button","toolbartestbutton");
button:setText( "Test" )
button:setSize( CEGUI.Size:new_local(0.5,0.1) )
button:setPosition( CEGUI.Point:new_local(0.0,0.8) )

button:setProperty( "NormalImage", "set:Editor image:ToolbarIcon1");


Hope that works, haven't actually tried it :)


Seems to work, thanks. I noticed that if the image of an imageset is not 128x128 or 256x256 then coordinates given in imageset xml-file don't really match. Is it a feature?

Posted: Wed Mar 08, 2006 21:47
by lindquist
3D hardware requires that texture have dimensions in powers of two

64x64, 128x128, 128x256, 256x256, 256x512 as so on...

The texture does'nt have to be square but both width and height must be a power of two.

If the image is'nt dimensioned like this it is scaled up to the nearest power of two on each axis. CEGUI does not currently take this scaling into account and "thinks" that the original pixel corrdinates still are valid.

I guess this should be considered a bug, but.. I would make sure that your texture just use 2^n dimensions as the auto scaling can make your texture look bad as well.

Posted: Thu Mar 09, 2006 00:32
by baxissimo
lindquist wrote:3D hardware requires that texture have dimensions in powers of two

64x64, 128x128, 128x256, 256x256, 256x512 as so on...

The texture does'nt have to be square but both width and height must be a power of two.


Any semi-recent NVIDIA card has support for the NV_texture_rectangle GL extension that allows for NPOT (non-power-of-two) textures. Is this supported by recent ATI cards also? [edit]It seems they do have something called EXT_texture_rectangle, which I'm guessing has the same functionality, and probably same API[/edit] It might be nice if CEGUI's GL renderer could use it when available when someone tries to use a non-power-of-two texture.

On second thought. Nevermind. It would be annoying to develop your whole app on your fancy NVIDIA card only to find out that all of your 260x260 textures are suddenly taking up 512x512 of texture memory when you run your app on Joe Consumer's ancient hardware.