Need some HUD help.

I need some help with antialiasing this HUD and Scaleing it propperly insted of the way it is being scaled now. Scaleing works but doesnt at the same time. The HUD code will be below.


I’ve tested your code and it appears that aliasing depends on the aliasing settings set in video options.

If you want aliased edges for all clients regardless of client settings, you should consider using a texture instead.

Can you be more clear what you mean by “scaling works but also doesn’t” ? If you want the HUD to scale perfectly and appear the same on all screens, you will need to scale all your static offsets (e.g. your triangle offsets) based on screen size. How you do that is up to you, but you should take either ScrH() or ScrW() and scaled based on that.

Also, for the love of god, move that hook.Add out of HUDPaint.

Do you mean this?

 hook.Add("HUDPaint", "DrawHUD", DrawHUD) 

I mean this
[lua]hook.Add( “HUDPaint”, “PolygonTest”, function() … end[/lua]

Being inside of
[lua]local function Polygons()[/lua]

And the aforementioned function being called inside your primary HUDPaint hook.

This means that the hook is being added every frame. While this shouldn’t be a major performance issue, there is virtually no reason for it to be like that. In fact, you can remove your triangle hook entirely, so that your function ends up being like that:
[lua]local function Polygons()

These are the polygon positions

local triangleback1 = {     
    { x = 256, y = ScrH()-55 },
    { x = 256, y = ScrH()-127 },
    { x = 456, y = ScrH()-55 }


local triangleback2 = {
    { x = ScrW() - 256, y = ScrH()-55 },
    { x = ScrW() - 456, y = ScrH()-55 },
    { x = ScrW() - 256, y = ScrH()-127 }


local trianglefront1 = {
    { x = 256, y = ScrH()-49 },
    { x = 256, y = ScrH()-120 },
    { x = 456, y = ScrH()-49 }


local trianglefront2 = {
    { x = ScrW() - 256, y = ScrH()-49 },
    { x = ScrW() - 456, y = ScrH()-49 },
    { x = ScrW() - 256, y = ScrH()-120 }


surface.SetDrawColor(255, 0, 0, 210)
surface.DrawPoly( triangleback1 )

surface.SetDrawColor(255, 0, 0, 210)
surface.DrawPoly( triangleback2 )

surface.DrawPoly( trianglefront1 )

surface.DrawPoly( trianglefront2 )


It will work the same way.

EDIT: Ideally, you should also move your triangle definitions (i.e. local triangle… = {…}) outside of any functions, above the function that draws them. Right now, since they are declared inside your functions as locals, they are recreated each time the function is called, incurring a small overhead.

Ok thanks for that. It worked withought the hook. On the gmod wiki it says that you require the hook to run that part of the script.

#Learning LUA

HUDs typically only require one HUDPaint hook, and draw all of the HUD elements inside of that. Most of the times, if you can squash two hooks into one without side effects, you by all means should do so.

Ah ok, any tips for learning more LUA?