• Problem with surface.DrawPoly()
    7 replies, posted
Hi ! I have a strang problem with surface.DrawPoly(), maybe someone could help me with it... Here is my code local LEFT_MENU = {} function LEFT_MENU:Init()   self:StretchToParent(0, SCREEN_HEIGHT * 1/6, SCREEN_WIDTH * 5/6, SCREEN_HEIGHT * 1/6)   self.Paint = function(pnl,w,h)     --draw.RoundedBox(0,0,0,w,h, Color(255,255,255,255))     local poly = {       { x = 0, y = 0},       { x = w - w * 1/10, y = 0},       { x = w, y = w * 1/10},       { x = w, y = h - w * 1/10},       { x = w - w * 1/10, y = h},       { x = 0, y = h},     }     surface.SetDrawColor( Color( 255, 0, 0, 255 ) )     surface.DrawPoly( poly )   end end vgui.Register( "LEFT_MENU", LEFT_MENU, "DPanel" ) Here is the output (not zoomed) and here is the output (zoomed) If you notice, the lign is not perfect at all ! I don't know where it comes from and how can i fix it, i tried with a lot of size but problem remains :/ Thanks in advance for any answer
Polygon edges are not antialiased and vertices are rounded to the nearest pixel. If you want a perfect diagonal line, make sure the slope between the two points is equal to 0.5 or -0.5 The slope of a line between two points is (y2-y1/x2-x1). Just like in middle school using y=mx+b
Ok, i will test that tomorrow thanks a lot, i have an other very strange problem, the red HUD is vanishing when a darkrp message is displayed, for exemple if i get the salary msg "You got 40$ as salary" or w/e message my hud drawn with surface.DrawPoly() disapear and when the message is gone it show up again ! What the hell is that ? :/
draw.NoTexture() before surface.DrawPoly()
THANKS A LOT BOBBLEHEAD! I was really scared about this sh*t ! Love you ! By the way i'm trying to figure out how i can have a slope of 0.5 or -0.5 in my case, but can achieve it with a responsive design ? I'm kind of shit with this type of math tbh. But i'm willing to learn
Oh my bad, I mean a perfect slope of 1 or -1 If it's not perfect, try doing math.floor() or math.ceil() to the x and y values. It might be rounding them up or down (to the nearest pixel) before it draws the shape without you knowing.
x = 383 / y = 0 x = 426 / y = 43 426 - 383 = 43 43 - 0 = 43 43/43 = 1 And i still have a fcked up diagonal !
Just use a texture then. surface.DrawPoly is best used for drawing dynamic shapes, not diagonal lines.
Sorry, you need to Log In to post a reply to this thread.