Code: Select all
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local msx = Game.mapSizeX
local msz = Game.mapSizeZ
local xformList = 0
local startboxDListStencil = 0
local startboxDListColor = 0
--------------------------------------------------------------------------------
GL.KEEP = 0x1E00
GL.INCR = 0x1E02
GL.DECR = 0x1E03
GL.INVERT = 0x150A
local stencilBit1 = 0x11
local stencilBit2 = 0x11
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local function DrawMyBox(minX,minY,minZ, maxX,maxY,maxZ)
gl.BeginEnd(GL.QUADS, function()
--// top
gl.Vertex(minX, maxY, minZ);
gl.Vertex(maxX, maxY, minZ);
gl.Vertex(maxX, maxY, maxZ);
gl.Vertex(minX, maxY, maxZ);
--// bottom
gl.Vertex(minX, minY, minZ);
gl.Vertex(minX, minY, maxZ);
gl.Vertex(maxX, minY, maxZ);
gl.Vertex(maxX, minY, minZ);
end);
gl.BeginEnd(GL.QUAD_STRIP, function()
--// sides
gl.Vertex(minX, minY, minZ);
gl.Vertex(minX, maxY, minZ);
gl.Vertex(minX, minY, maxZ);
gl.Vertex(minX, maxY, maxZ);
gl.Vertex(maxX, minY, maxZ);
gl.Vertex(maxX, maxY, maxZ);
gl.Vertex(maxX, minY, minZ);
gl.Vertex(maxX, maxY, minZ);
gl.Vertex(minX, minY, minZ);
gl.Vertex(minX, maxY, minZ);
end);
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function widget:Initialize()
-- flip and scale (using x & y for gl.Rect())
xformList = gl.CreateList(function()
gl.LoadIdentity()
gl.Translate(0, 1, 0)
gl.Scale(1 / msx, -1 / msz, 1)
end)
local xn, zn, xp, zp = 0,200,400,600
local minY,maxY = Spring.GetGroundExtremes()
startboxDListStencil = gl.CreateList(function()
if (xn and ((xn ~= 0) or (zn ~= 0) or (xp ~= msx) or (zp ~= msz))) then
gl.StencilMask(stencilBit1);
gl.StencilFunc(GL.ALWAYS, 0, stencilBit1);
DrawMyBox(xn,minY,zn, xp,maxY,zp)
end
end)
startboxDListColor = gl.CreateList(function()
if (xn and ((xn ~= 0) or (zn ~= 0) or (xp ~= msx) or (zp ~= msz))) then
gl.Color( 0, 0, 1, 0.3 ) -- red
gl.StencilMask(stencilBit1);
gl.StencilFunc(GL.NOTEQUAL, 0, stencilBit1);
DrawMyBox(xn,minY,zn, xp,maxY,zp)
end
end)
end
function widget:Shutdown()
gl.DeleteList(xformList)
gl.DeleteList(startboxDListStencil)
gl.DeleteList(startboxDListColor)
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function widget:DrawWorldPreUnit()
gl.Fog(false)
gl.DepthMask(false);
if (gl.DepthClamp) then gl.DepthClamp(true); end
gl.DepthTest(true);
gl.StencilTest(true);
gl.ColorMask(false, false, false, false);
gl.Culling(false);
gl.StencilOp(GL.KEEP, GL.INVERT, GL.KEEP);
gl.CallList(startboxDListStencil); --// draw
gl.Culling(GL.BACK);
gl.DepthTest(false);
gl.ColorMask(true, true, true, true);
gl.CallList(startboxDListColor); --// draw
if (gl.DepthClamp) then gl.DepthClamp(false); end
gl.StencilTest(false);
gl.DepthTest(true);
gl.Culling(false);
gl.Fog(true)
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function widget:DrawInMiniMap(sx, sz)
gl.PushMatrix()
gl.CallList(xformList)
gl.LineWidth(1.49)
-- show all start boxes
local xn, zn, xp, zp = 0,200,200,400
if (xn and ((xn ~= 0) or (zn ~= 0) or (xp ~= msx) or (zp ~= msz))) then
color = { 0, 0, 1, 0.1 } -- red
gl.Color(color)
gl.Rect(xn, zn, xp, zp)
color[4] = 0.5 -- pump up the volume
gl.Color(color)
gl.PolygonMode(GL.FRONT_AND_BACK, GL.LINE)
gl.Rect(xn, zn, xp, zp)
gl.PolygonMode(GL.FRONT_AND_BACK, GL.FILL)
end
gl.PushAttrib(GL_HINT_BIT)
gl.Smoothing(true) --enable point smoothing
gl.LineWidth(1.0)
gl.PointSize(1.0)
gl.PopAttrib() --reset point smoothing
gl.PopMatrix()
end
- why a 3d box in space for the box? why not project a quad on the ground?
- what the devil is this
Code: Select all
GL.KEEP = 0x1E00 GL.INCR = 0x1E02 GL.DECR = 0x1E03 GL.INVERT = 0x150A local stencilBit1 = 0x11 local stencilBit2 = 0x11
- why 2 display lists?