UI Texturing
Posted: 08 Apr 2011, 00:22
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