Team Spartan Cookies & Milk Forums
drawPoly - Printable Version

+- Team Spartan Cookies & Milk Forums (https://teamscm.co.uk)
+-- Forum: Garry's Mod (https://teamscm.co.uk/forum-4.html)
+--- Forum: Starfall (https://teamscm.co.uk/forum-7.html)
+--- Thread: drawPoly (/thread-871.html)



drawPoly - Destiny's Player - 16-04-2015

Good morning. I've been trying to find information on this for a pretty long time (A few hours... Yeah, not as long as it could be, but still). So, here's a question. How on earth do you use drawPoly? I know that you need to use render.createPoly({render.Vertex(x,y,u,v)...}), but... I can't understand what do the u and v parameters mean. And also, if they aren't important for basic use, then I can't get the poly to show up non-black, or even at all.

Here's the code I'm trying to get to work.
--@name Testing
--@author TheNextDecade
--@sharedscreen

if CLIENT then
local function Hexagon(posx,posy,col)
local top = posy-30
local bot = posy+30
local tbleft = posx-20
local tbright = posx+20
local midleft = posx-35
local midright = posx+35

render.setColor(255,255,255,150)

local Test = render.createPoly({
render.vertex(top,tbleft),
render.vertex(top,tbright),
render.vertex(posy,midright),
render.vertex(bot,tbright),
render.vertex(bot,tbleft),
render.vertex(posy,midleft)
})
render.drawPoly(Test)

--[[
render.drawLine(posx,top,posx,bot)
render.setColor(col[1],col[2],col[3],col[4])
render.drawLine(tbleft,top,tbright,top)
render.drawLine(tbleft,bot,tbright,bot)
render.drawLine(tbleft,top,midleft,posy)
render.drawLine(tbright,top,midright,posy)
render.drawLine(tbleft,bot,midleft,posy)
render.drawLine(tbright,bot,midright,posy)
]]--


end


hook("render","Render",function()
render.clear()
render.setTexture()
local ColVec = {100,255,255,255}
Hexagon(200,200,ColVec)
end)
end



RE: drawPoly - LocInt - 16-04-2015

Are you sure the vertices are in the right order? Go round the shape clockwise starting at the top left.

Person's example:
Code:
{ render.vertex( 124, 9 ), render.vertex( 154, 9 ), render.vertex( 142, 21 ), render.vertex( 112, 21 ) }



RE: drawPoly - Destiny's Player - 17-04-2015

Yep, I'm sure that it's from top-left to middle-left, as it's a hexagon.

LATER: Heh. Found out why on earth it doesn't work. You have to start not at the top, but at the bottom.

--i.e. not:
render.poly({
render.vertex(70,80),
render.vertex(70,120),
render.vertex(100,135),
render.vertex(130,120),
render.vertex(130,80),
render.vertex(100,65)
})
--but
render.poly({
render.vertex(130,80),
render.vertex(130,120),
render.vertex(100,135),
render.vertex(70,120),
render.vertex(70,80),
render.vertex(100,65)
})
And from what I can tell, you have to go counter-clockwise, not clockwise.


RE: drawPoly - Person8880 - 17-04-2015

The shape you've given is going clockwise, not counter-clockwise. It is definitely clockwise that is the requirement.


RE: drawPoly - Destiny's Player - 17-04-2015


local top = posy-30
local bot = posy+30
local tbleft = posx-20
local tbright = posx+20
local midleft = posx-35
local midright = posx+35

render.vertex(tbright,bot),
render.vertex(tbleft,bot),
render.vertex(midleft,posy),
render.vertex(tbleft,top),
render.vertex(tbright,top),
render.vertex(midright,posy)

Yep, looking at it, it's definately clockwise. But still, it's interesting that it requires starting from bottom-right, and when I try top-left it doesn't work...


RE: drawPoly - Person8880 - 17-04-2015

The following code:

local function MakeHexagon( X, Y, W, H )
return {
render.vertex( X, Y - H * 0.5 ),
render.vertex( X + W * 0.5, Y - H * 0.25 ),
render.vertex( X + W * 0.5, Y + H * 0.25 ),
render.vertex( X, Y + H * 0.5 ),
render.vertex( X - W * 0.5, Y + H * 0.25 ),
render.vertex( X - W * 0.5, Y - H * 0.25 )
}
end

local Poly = MakeHexagon( 256, 256, 128, 128 )
hook( "render", "bleh", function()
render.clear( 0, 0, 0, 255 )

render.setTexture()
render.setColor( 255, 255, 255 )

render.drawPoly( Poly )

hook( "render", "bleh" )
end )

draws a hexagon happily in the centre of a screen. The vertices are in clockwise order starting from the top left (in this case, more top-centre, but the general rule is upper-leftmost), so it definitely does work.

I'm not 100% sure about top-left being an absolute requirement, but I do know that clockwise is. I go with what's always worked, and top-left clockwise has never failed me.


RE: drawPoly - Destiny's Player - 17-04-2015

Thanks for the help! On the first sleepy glance, your code is cleaner and has an easy to change scale feature. I'll look into it more tomorrow, but still, thanks a lot.
Also, a small question. What's the purpose of the second render hook in the second-to-last row?