# surface.DrawPoly

 Function Syntax surface.DrawPoly( Table vertex data structure ) Description: Draws a textured polygon by drawing each vertex specified within the table, then filling in the area. Returns: nil Part of Library: surface Realm: BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Surface.DrawPoly]Surface.DrawPoly [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]

## Examples

Description This will draw a right triangle on the center of the HUD. ```  triangletex = surface.GetTextureID( PICK A TEXTURE PATH ) -- this is our triangles texture, try to find your own centerx = ScrW()/2 --this is the middle x cordinate centery = ScrH()/2 --this is the middle y cordinate trianglevertex = {{ },{ },{ }} --create the two dimensional table   --First Vertex trianglevertex["x"] = centerx trianglevertex["y"] = centery trianglevertex["u"] = 0 //Top Left trianglevertex["v"] = 0   --Second Vertex trianglevertex["x"] = centerx + 50 trianglevertex["y"] = centery trianglevertex["u"] = 1 //Top Right trianglevertex["v"] = 0   --Third Vertex trianglevertex["x"] = centerx trianglevertex["y"] = centery + 50 trianglevertex["u"] = 0 //Bottom Left trianglevertex["v"] = 1   local function HUDPaint()   surface.SetTexture( triangletex ) --set the texture of the triangle surface.SetDrawColor( 255, 255, 255, 255 ) --set the additive color surface.DrawPoly( trianglevertex ) --draw the triangle with our triangle table   end hook.Add("HUDPaint","Draw Triangle", HUDPaint)  ``` N/A

Description This will generate a polygon ready to draw. ```  local sin,cos,rad = math.sin,math.cos,math.rad; --Only needed when you constantly calculate a new polygon, it slightly increases the speed. function GeneratePoly(x,y,radius,quality) local circle = {}; local tmp = 0; for i=1,quality do tmp = rad(i*360)/quality circle[i] = {x = x + cos(tmp)*radius,y = y + sin(tmp)*radius}; end return circle; end  ``` N/A

Description This will generate a polygon ready to draw, with uv mapping. ```  local sin,cos,rad = math.sin,math.cos,math.rad local function GeneratePoly(x,y,radius,quality) local circle = {}; local tmp = 0; local s,c; for i=1,quality do tmp = rad(i*360)/quality; s = sin(tmp); c = cos(tmp); circle[i] = {x = x + c*radius,y = y + s*radius,u = (c+1)/2,v = (s+1)/2}; end return circle; end  ``` N/A

• Texture Coordinates:

The U and V components are used to control how the texture is rendered on the polygon. EG Setting U,V to 0,0 will have the texture top left corner drawn at that vertex.

For most situations you should use the UV coordinates (0,0) (0,1) (1,1) (1,0) for top-left, top-right, bottom right and bottom left coordinates, respectively.

Using values larger than 1 will repeat the texture, values less than 1 for parts of the texture.

If you are not using a texture you can leave them blank

• Vertex Data Structure: The table structure for this function is a two-dimensional table,
```table ={
[vertex number] = { you may have any number of vertices
x= x position of vertex
y= y position of vertex
u= horizontal texture cordinate
v= vertical texture cordinate
}
}```
• You can have a maximum amount of 256 vertices.
• If you aren't using a texture, then you should call surface.SetTexture() before you use this. If this function appears to be not working, this might be why.
• The polygon MUST be convex for it to work properly.