Team Spartan Cookies & Milk Forums
  • Issue Tracker
  • Donations
  • Search
  • Member List
  • Help

Register

Team Spartan Cookies & Milk Forums Garry's Mod Starfall v
« Previous 1 … 14 15 16 17 18 Next »
drawPoly
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Threaded Mode
drawPoly
16-04-2015, 09:05 PM, (This post was last modified: 17-04-2015, 02:25 PM by Destiny's Player.)
#1
Destiny's Player Offline
A passing by member
***
Posts: 237
Threads: 35
Joined: Dec 2013
drawPoly
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
Find
Reply
16-04-2015, 10:18 PM, (This post was last modified: 16-04-2015, 10:19 PM by LocInt.)
#2
LocInt Offline
Long gone
****
Posts: 489
Threads: 91
Joined: Aug 2014
RE: drawPoly
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 ) }

тѕсм.Person8880 hovers the nerf bat over Tetryon damage
Website Find
Reply
17-04-2015, 06:09 AM, (This post was last modified: 17-04-2015, 02:25 PM by Destiny's Player.)
#3
Destiny's Player Offline
A passing by member
***
Posts: 237
Threads: 35
Joined: Dec 2013
RE: drawPoly
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.
Find
Reply
17-04-2015, 06:12 PM,
#4
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: drawPoly
The shape you've given is going clockwise, not counter-clockwise. It is definitely clockwise that is the requirement.
Find
Reply
17-04-2015, 08:51 PM,
#5
Destiny's Player Offline
A passing by member
***
Posts: 237
Threads: 35
Joined: Dec 2013
RE: drawPoly

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...
Find
Reply
17-04-2015, 09:49 PM,
#6
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: drawPoly
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.
Find
Reply
17-04-2015, 09:53 PM, (This post was last modified: 17-04-2015, 10:00 PM by Destiny's Player.)
#7
Destiny's Player Offline
A passing by member
***
Posts: 237
Threads: 35
Joined: Dec 2013
RE: drawPoly
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?
Find
Reply
« Next Oldest | Next Newest »


  • View a Printable Version
Forum Jump:


Users browsing this thread: 1 Guest(s)
Contact UsTeam Spartan Cookies & MilkReturn to TopLite (Archive) ModeMark all forums readRSS Syndication

Powered By MyBB, © 2002-2026 MyBB Group.