Positioning DrawPoly

So I want to know if there is any easier way to position a DrawPoly. Also how I can make it in the same spot (Bottom left) on every screen, rather than it moving if I change resolutions (In windowed mode)

Currently im just using this piece of code:



local triangle = {
	{ x = 30, y = 825 },
	{ x = 285, y = 825 },
	{ x = 305, y = 840 },
	{ x = 285, y = 855 },
	{ x = 30, y = 855 }
}

hook.Add( "HUDPaint", "PolygonTest", function()
	surface.SetDrawColor( 255, 0, 0, 255)
	draw.NoTexture()
	surface.DrawPoly( triangle )
end )


Sadly there’s no easier way. You just have to change the X and Y coordinates based on

ScrW and

ScrH.

[editline]27th August 2017[/editline]

If you want the triangle poly to update every frame (which you probably do), then just create that table in the HUDPaint hook.

That sucks. But thanks for the reply

Just wondering, what do you mean by ‘an easier way’? All of the drawing libraries in Garry’s Mod use x and y coordinates like DrawPoly does. How would you like it to work? I’m sure there’s a way to do it how you want with a simple wrapper function

You could use a Matrix to scale things, however, the 2d drawing functions seem to cast numbers to integers, so you may only be able to use whole numbers.



local m = Matrix()
m:Scale(Vector(100, 100, 1))

local function paint()
	cam.PushModelMatrix(m)
	surface.SetDrawColor(255, 255, 255, 255)
	surface.DrawRect(0, 0, 1, 1)
	cam.PopModelMatrix()
end

hook.Add("HUDPaint", "Test", paint)


This gives you a 100x100 white rectangle.

Actually, according to the wiki, it seems that DrawPoly doesn’t round the coordinates unlike the rest of the functions.

Well there you go, looks like a perfect solution then (for DrawPoly).

Well, I’m new to the gmod scripting, and when you have 4 or 5 points that you need to position in a certain way to make a shape, it’s just a little hard to figure out the x and y of each point for me

Edit:
I found a script where you draw the poly through a derma panel, and it in turn gives you the x and y coordinates, but it wont fit universal screen resolutions