gl.Unit / gl.UnitRaw question

gl.Unit / gl.UnitRaw question

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

Moderator: Moderators

Post Reply
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

gl.Unit / gl.UnitRaw question

Post by Niobium »

I've been trying to use these functions to draw exact copies of units, however the best I can get is a non-textured version. Is there some simple step I am missing / some way to texture them with right texture? Or is this the best that can be done?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: gl.Unit / gl.UnitRaw question

Post by Argh »

gl.Texture(1,"%unitDefID:0") --texture 1
gl.Texture(2,"%unitDefID:1") --texture 2

Send both to your shader and process. To get exact copies of the Units, you probably need to look up jK's shader framework (which I am working on more when I am not so busy) which has a S3O GLSL shader that behaves exactly like the ARB shader.
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: gl.Unit / gl.UnitRaw question

Post by Niobium »

Argh wrote:gl.Texture(1,"%unitDefID:0") --texture 1
gl.Texture(2,"%unitDefID:1") --texture 2

Send both to your shader and process. To get exact copies of the Units, you probably need to look up jK's shader framework (which I am working on more when I am not so busy) which has a S3O GLSL shader that behaves exactly like the ARB shader.
Unfortunately I don't know anything about shaders. Im not after anything fancy like shadows/reflection/lighting/alpha/etc, just a textured model of the unit is all I need, so is there any shortcut/simple way to get just that?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: gl.Unit / gl.UnitRaw question

Post by Argh »

Oh, well... if you don't need lighting or anything, then this should get you close.

Code: Select all

Spring.UnitRendering.SetUnitLuaDraw(unitID,true)
gl.DepthTest(GL.LEQUAL)
gl.Texture(1,"%unitDefID:0")
gl.Color(1.0,1.0,1.0,1.0)
gl.Unit(unitID,true)
...just be prepared, it will not look all that cool.
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: gl.Unit / gl.UnitRaw question

Post by Niobium »

It seems Spring.UnitRendering is nil for me?

But then I am not trying to change the drawing of the unit, I'm trying to draw a copy of it, so I don't know if that function would help anyway. Thanks anyway.

In the meantime I've solved my problem with something different but more than adequate; Drawing the unit with polygonmode fill and some solid color, then polygonmode line with color black. Sure doesn't have any of the details, but the unit is still easily recognizable.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: gl.Unit / gl.UnitRaw question

Post by zwzsg »

Code: Select all

-- Draw an armstump, with the color of team team, at the position x,y,z
-- This use an unitDef, not an unit,
-- so on one hand it doesn't copy the exact poses of all the pieces of a live unit,
-- but on the other you don't need any live instance of that unit type.

	gl.Translate(x,y,z)
	gl.UnitShape(UnitDefNames.armstump.id,team)
	gl.Translate(-x,-y,-z)

Code: Select all

-- Draw a copy of a live unit (untested)

local function DrawUnitCopy(unitID,x,y,z)
		gl.PushMatrix()
		local ux,uy,uz=Spring.GetUnitPosition(unitID)
		gl.Translate(x-ux,y-uy,z-uz) -- There's also gl.Scale if you want to draw bigger/smaller
		gl.Blending(GL.ONE_MINUS_SRC_COLOR,GL.ONE) -- That was to make it look holographic, remove if you want it solid
		gl.Unit(unitID)
		gl.Blending(GL.SRC_ALPHA,GL.ONE_MINUS_SRC_ALPHA)
		gl.PopMatrix()
end
Post Reply

Return to “Lua Scripts”