Lines on the edge of my texrect?

Lines on the edge of my texrect?

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

Moderator: Moderators

Post Reply
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Lines on the edge of my texrect?

Post by smoth »

Image
Click picture for larger image

so I have no idea where these ugly lines are coming from... They are not part of the images.

Here is my REALLY WIP code:

Code: Select all

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

-- Automatically generated local definitions
local spGetLocalTeamID		= Spring.GetLocalTeamID
local spIsGUIHidden			= Spring.IsGUIHidden
local spGetModOptions		= Spring.GetModOptions

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

function gadget:GetInfo()
	return {
		name = "Heads up Display",
		desc = "hitpoints and junk",
		author = "Smoth (Steve Smith), regret, lurker",
		date = "2009-9-1",
		license = "PD",
		layer = 0,
		enabled = true
	}
end

local makeMinimapStatic = true
_G.resupplyString = "?"
local resupplyResourceUpdates = 0
local resupplyPeriod = 9000 -- default to 5 minutes
local recentSupplyUse = 0

local mCurr, mStor, mPull, mInco, mExpe, mShar, mSent, mReci
local eCurr, eStor, ePull, eInco, eExpe, eShar, eSent, eReci

local UIVAR = {
-- general crap
	GEN = {	FONT,	},
-- minimap
	MMP = {	px, py, sx, sy, aspect,	},
--minimap frame
	MM = {	px, py, sy,	sx,	},
--info box
	IB = {	px, py, sy,	sx,	},
--details box
	DTB = {	px, py, sy,	sx,	},
	
--Res bar
	RB = {	px, py, sy,	sx,	},	
}
	
local baseWidth		= 1024
local baseHeight	= 768
local myTeamID 
		
local function FramesToTimeString(n)
	local seconds = n / 30
	return string.format(math.floor(seconds / 60) .. ":" .. string.format("%02i", math.ceil(seconds % 60)))
end
	
function gadget:GameFrame(n)
_G.resupplyString = FramesToTimeString(resupplyPeriod - n % resupplyPeriod)

	if ((resupplyPeriod - n % resupplyPeriod) % 32 == 0) then
		resupplyResourceUpdates = (resupplyPeriod - n % resupplyPeriod) / 32
		UpdateResources()
	end
end	
	
	function UpdateResources()
		if ( myTeamID ) then
			mCurr, mStor, mPull, mInco, mExpe, mShar, mSent, mReci = Spring.GetTeamResources(myTeamID, "metal")
			eCurr, eStor, ePull, eInco, eExpe, eShar, eSent, eReci = Spring.GetTeamResources(myTeamID, "energy")
			recentSupplyUse = recentSupplyUse * (supplyEstimateDecayTime - 1) / supplyEstimateDecayTime  + ePull / supplyEstimateDecayTime
		end
	end	
if not gadgetHandler:IsSyncedCode() then

	local vsx,vsy = gl.GetViewSizes()
	myTeamID = Spring.GetMyTeamID()
	
	if (vsx == 1) then --hax for windowed mode
		vsx,vsy = Spring.GetWindowGeometry()
	end
	
	
	local glColor          = gl.Color 
	local glRect           = gl.Rect
	local glTexRect        = gl.TexRect
	local glText           = gl.Text
	local glTexture        = gl.Texture	

	function setMinimapVals()
	-- _, _, UIVAR.MMP.SX, UIVAR.MMP.SY = Spring.GetMiniMapGeometry()
	
		-- if ( UIVAR.MMP.SX == UIVAR.MMP.SY ) then
		
			UIVAR.MMP.px	= (vsy/59.076923076923076923076923076923)+1
			UIVAR.MMP.py	= (vsy/59.076923076923076923076923076923)+1	
			UIVAR.MMP.sx	= UIVAR.MMP.py + (vsy/4.49)
			UIVAR.MMP.sy	= UIVAR.MMP.py + (vsy/4.49)
			
			border	= UIVAR.MMP.px
			
			UIVAR.GEN.FONT	= vsy/64
			
			--  orientation based on the upper left corner
			UIVAR.MM.px		= 0
			UIVAR.MM.py		= vsy - (vsy/3.65)
			UIVAR.MM.sx		= vsy - UIVAR.MM.py
			UIVAR.MM.sy		= vsy
								
			UIVAR.RB.px		= UIVAR.MM.sx
			UIVAR.RB.py		= vsy - vsy/12.8
			UIVAR.RB.sy		= vsy
			UIVAR.RB.sx		= UIVAR.MM.sx + (vsy/2.4458598726114649681528662420382)
								
			UIVAR.IB.px		= 0
			UIVAR.IB.py		= UIVAR.MM.py - vsy/23.272727272727272727272727272727
			UIVAR.IB.sx		= UIVAR.MM.sx
			UIVAR.IB.sy		= UIVAR.MM.py+1

			-- this should be a new base orientation based on the upper right corner
			UIVAR.DTB.px		= vsx - (vsy/1.8070588235294117647058823529412)
			UIVAR.DTB.py		= vsy - (vsy/8.1702127659574468085106382978723)
			UIVAR.DTB.sx		= vsx
			UIVAR.DTB.sy		= vsy
								
		-- end
		for setName,set in pairs(UIVAR) do
		Spring.Echo("_______________________")
			for name, key in pairs(set) do
				Spring.Echo(setName .. "." .. name .. ": " .. key)
			end
		end
		
	end

	function gadget:ViewResize(viewSizeX, viewSizeY)
		vsx,vsy = gl.GetViewSizes()

		setMinimapVals()
		Spring.SendCommands(string.format("minimap geometry %i %i %i %i",UIVAR.MMP.px,UIVAR.MMP.py,UIVAR.MMP.sx,UIVAR.MMP.sx))
		Spring.SendCommands({"minimapbuttonsize " .. 222})
		Spring.Echo("resized")
	end
	

	function gadget:Initialize()
		oldMinimapGeometry = Spring.GetConfigString("MiniMapGeometry","2 2 200 200") -- store original geometry
		setMinimapVals()
		Spring.SendCommands(string.format("minimap geometry %i %i %i %i",UIVAR.MMP.px,UIVAR.MMP.py,UIVAR.MMP.sx,UIVAR.MMP.sy))
		
		if (makeMinimapStatic) then
			gl.SlaveMiniMap(true)
		end

	end
	
	function gadget:UnitCreated(unitID, unitDefID, unitTeam, builderID)
		local unitDef = UnitDefs[unitDefID]
		if (unitDef.customParams.hq == '1') then
			resupplyPeriod = tonumber(unitDef.customParams.arrivalgap) * 30
		end
	end


	
	function gadget:DrawScreen(ScreenSizeX, ScreenSizeY)
		if (makeMinimapStatic) then
			-- this makes jK rage
			gl.ResetState()
			gl.ResetMatrices()
			--
			gl.DrawMiniMap()
			-- this makes jK rage
			gl.ResetState()
			gl.ResetMatrices()
			----
		end
		
		if not spIsGUIHidden() then
			local phase = 0
			phase = phase + .1
			local team = spGetLocalTeamID()
			glColor(1,1,1,1)

			glTexture('ui/images/minimap.png'); 
			glTexRect( UIVAR.MM.px, UIVAR.MM.py, UIVAR.MM.sx, UIVAR.MM.sy)	

			glTexture('ui/images/bar.png'); 
			glTexRect( UIVAR.IB.px, UIVAR.IB.py, UIVAR.IB.sx, UIVAR.IB.sy)	

			glTexture('ui/images/resbar.png'); 
			glTexRect( UIVAR.RB.px, UIVAR.RB.py, UIVAR.RB.sx, UIVAR.RB.sy)	
			
			glTexture('ui/images/info.png'); 
			glTexRect( UIVAR.DTB.px, UIVAR.DTB.py, UIVAR.DTB.sx, UIVAR.DTB.sy)	
			-- glText("\255\255\10\10" ..SYNCED.resupplyString, UIVAR.BB.sx + UIVAR.MMP.sx/60, UIVAR.BB.py + UIVAR.MMP.sx/23, UIVAR.GEN.FONT, "O")
			-- Spring.Echo(SYNCED.resupplyString)
			-- while () do
			
			-- end 
			--0, 205.10417175293, 299.98699951172, 49.21875
			-- resource numbers
			-- if (SYNCED.deaths[team]) then
				-- glText(SYNCED.deaths[team], ScreenSizeX-30, ScreenSizeY-80, 12, "ro")
			-- end
			
			-- if (SYNCED.kills[team] ) then
				-- glText(SYNCED.kills[team], ScreenSizeX-30, ScreenSizeY-115, 12, "ro")
			-- end
		end
		glColor(1,1,1,1)
	end	

	function gadget:Shutdown()
		if (makeMinimapStatic) then
			gl.SlaveMiniMap(false)
		end
		Spring.SendCommands("minimap geometry "..oldMinimapGeometry) -- restore to original geometry, not really needed
	end
end
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Lines on the edge of my texrect?

Post by zwzsg »

I had the same problem.

IIRC the issue is that the texture is smoothed, the pixels are blurred with their neighbours. And the neighbour of the pixels at the edge, are the pixels on the opposite edge. To workaround these, I used:

gl.TexRect(x1,y1,x2,y2,0.01,0.99,0.99,0.01)

instead of:

gl.TexRect(x1,y1,x2,y2,0,1,1,0)
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Lines on the edge of my texrect?

Post by smoth »

apparently the scaling is causing spill over because of "issues with clamping" is what I am being told. Any way to address this beyond 1-2 pixel borders on my images?
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6243
Joined: 29 Apr 2005, 01:14

Re: Lines on the edge of my texrect?

Post by FLOZi »

This has been resovled in #lua, for the sake of forum goers:
[02:44:14] <[LCC]jK> gl.Texture(":c:" .. filepath)
[02:44:24] <[LCC]jK> c = clamp
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Lines on the edge of my texrect?

Post by smoth »

oh sorry, forgot to post the solution. My apologies.
Post Reply

Return to “Lua Scripts”