drawing lines wont show

drawing lines wont show

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

Moderator: Moderators

Post Reply
PixelOfDeath
Posts: 24
Joined: 27 Nov 2011, 10:38

drawing lines wont show

Post by PixelOfDeath »

I can't get my widget to draw lines.
Very simple example:

Code: Select all

local function TestDraw()
	gl.Color({1,1,1,0})
	for sniper in pairs(sniperList) do
		local x, y, z = Spring.GetUnitPosition(sniper)

		gl.Vertex(x,y,z+1000)
		gl.Vertex(x,y,z-1000)
		gl.Vertex(x,y+1000,z)
		gl.Vertex(x,y-1000,z)
		gl.Vertex(x+1000,y,z)
		gl.Vertex(x-1000,y,z)
	end
end

function widget:DrawWorldPreUnit()
	gl.DepthTest(true)
	gl.BeginEnd(GL.LINE, TestDraw)
end
the part with the gl.Vertex gets called and the x,y,z values are ok. But there is nothing visible on screen. What am I doing wrong?

The OpenGL coordinates and the unit positions are the same I suppose!?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: drawing lines wont show

Post by knorke »

gl.Color({1,1,1,0})
the last 0 makes your color fully transparent ;)
and need to set LineWidth

not good with gl but i tested like this and it draws a cross thing:
(uncomment the 2 lines if you dont want it visible through terrain)

Code: Select all

local function TestDraw()
   gl.Color({1,1,1,0.5})
   --for sniper in pairs(sniperList) do
      local x, y, z = 100,100,100 --Spring.GetUnitPosition(sniper)
      gl.Vertex(x,y,z+1000)
      gl.Vertex(x,y,z-1000)
      gl.Vertex(x,y+1000,z)
      gl.Vertex(x,y-1000,z)
      gl.Vertex(x+1000,y,z)
      gl.Vertex(x-1000,y,z)
   --end
end

function widget:DrawWorldPreUnit()   
   		gl.PushAttrib(GL_LINE_BITS)	
		--gl.DepthTest(true)
		gl.Color(1,0,1,0.5)
		gl.LineWidth(10)
		gl.BeginEnd(GL.LINES, TestDraw)	
		--gl.DepthTest(false)
		gl.Color(1,1,1,1)	
		gl.PopAttrib()   
end
The OpenGL coordinates and the unit positions are the same I suppose!?
yes
PixelOfDeath
Posts: 24
Joined: 27 Nov 2011, 10:38

Re: drawing lines wont show

Post by PixelOfDeath »

You solved it without saying what it was xD

GL.LINES and not GL.LINE

Because GL.LINE is a valid opengl constant, this one was hard to catch.

Thx
Post Reply

Return to “Lua Scripts”