hmm why wont this surface.DrawPoly() work?

I am trying to use surface.DrawPoly() for the first time and it doesnt seem to draw anything.


surface.SetDrawColor(0, 255, 0, 255)
surface.DrawPoly({ {100, 100}, {200, 100}, {200, 200}, {100, 200} })


damn Preview Post button removing the [LUA] tags everytime :c fix it robotboy D:

Look at http://wiki.garrysmod.com/page/Structures/PolygonVertex

[LUA]
positions = {}
positions[0] = {}
positions[0][“x”] = 100
positions[0][“y”] = 100

positions[1] = {}
positions[1][“x”] = 100
positions[1][“y”] = 100

positions[2] = {}
positions[2][“x”] = 100
positions[2][“y”] = 100

surface.SetDrawColor(0, 255, 0, 255)
surface.DrawPoly(positions)
[/LUA]

should be working

surface.DrawPoly doesn’t take a table of coordinates. It takes a table of specific structures called PolygonVertex. They still need to ordered like you did in your script.

Could you give me a working example?

Second post.

it doesnt work, do i like need to have no material set or stuff like that?

Obviously. You can use draw.NoTexture()

great, i still cant get it to work

Did you adjust the Coordinates?

I got it! @johnnyaka your example didnt work because the table needs to start from index 1 not 0.

And i think this is a much better way of writing the tables:


local poly1 = { {x=100, y=100}, {x=200, y=100}, {x=200, y=200}, {x=100, y=200} } // outside of drawing hook
surface.DrawPoly(poly1)


I hate Lua…it’s not like every other language is starting with 0

Well, I think that’s a matter of opinion :wink: