UI Texturing

UI Texturing

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

Moderator: Moderators

Post Reply
Freezerburn
Posts: 20
Joined: 26 Jan 2011, 20:25

UI Texturing

Post by Freezerburn »

What is the proper way to create a textured UI in Lua Widgets? I looked up the gl.Texture and gl.CreateTexture call-outs in the wiki, but I'm confused as to how exactly I should be using them. I was also looking through the Kernel Panic code, and noticed the code: gl.Texture(someTextureString) without any texture creation and I attempted to replicate that in my own code, but just ended up with a mostly-transparent white box in my UI. Here's the code for what I'm currently doing:

Code: Select all

local testtex = "LuaUI/Images/test.png"
function widget:DrawScreen()
	if once == false then
		local data = gl.TextureInfo( testtex )
		echo( "TEXTURE INFO - " .. data.xsize .. ", " .. data.ysize )
		-- I have the above code just for debuggin. It outputs -1,-1 for the sizes
		once = true
	end
	DrawTexRect(testxmin, testymin, testxmax, testymax, testtex, 0.3)
end

-- Credit goes to jK and zwzsg for this function. This code was taken
-- from their "kp_buildbar.lua" file from their "Kernel Panic" mod for
-- the Spring engine.
function DrawTexRect(left,top,right,bottom, texture, alpha)
  gl.Texture(true)
  gl.Texture(texture)
  gl.Color(1,1,1,alpha or 1)
  gl.TexRect(left,bottom,right,top)
  gl.Color(1,1,1,1)
  gl.Texture(false)
end
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: UI Texturing

Post by zwzsg »

The texture isn't created, instead someTextureString is the path and filename of the image to use. Are you sure you have the file "LuaUI/Images/test.png" present and a valid PNG?

Otherwise yeah it should be as simple as:
gl.Color(1,1,1,1)
gl.Texture("bitmaps/icons/frame.png")
gl.TexRect(x1,y1,x2,y2,0,1,1,0)
gl.Texture(false)
Freezerburn
Posts: 20
Joined: 26 Jan 2011, 20:25

Re: UI Texturing

Post by Freezerburn »

zwzsg wrote:The texture isn't created, instead someTextureString is the path and filename of the image to use. Are you sure you have the file "LuaUI/Images/test.png" present and a valid PNG?

Otherwise yeah it should be as simple as:
gl.Color(1,1,1,1)
gl.Texture("bitmaps/icons/frame.png")
gl.TexRect(x1,y1,x2,y2,0,1,1,0)
gl.Texture(false)
I have no idea what the problem was, but after commenting the line that outputs the x/y sizes and the gl.Texture(true) line and a restart of Spring, the image is now displaying. Maybe Spring just needed to restart to update the VFS or something? Not sure, but it seems to be working. Thanks for your help!
Post Reply

Return to “Lua Scripts”