surface.DrawPoly woes

[lua] local height,width,top = 40, 300, 200
function GM:PaintHealth()
local hp = lpl:Health()
local top = ScrH() - top
surface.SetDrawColorC(self.HUDBackground)
surface.DrawPoly{ – #1
{ x = 0; y = top };
{ x = width + 20, y = top };
{ x = width, y = top+height };
{ x = 0, y = top+height };
}
surface.DrawPoly{ – #2
{ x = 0; y = 0 };
{ x = 0; y = 10};
{ x = 10; y = 10};
{ x = 10; y = 0 };
}
surface.DrawRect(0,top+height,width,height) – #3
end[/lua]
only draws #3
while
[lua] local basetop, baseheight, width, hwidth = 8, 28, 360, 180
function GM:PaintCompass()
local yaw, top, height, centre = EyeAngles().y,basetop, baseheight,ScrW()/2
for ent,name in pairs(compassents) do
if not IsValid(ent) then
compassents[ent] = nil
else
height = height + 12
end
end
surface.SetDrawColorC(self.HUDBackground)
surface.DrawPoly{
{ x = centre-(hwidth + 20); y = 0};
{ x = centre+(hwidth + 20); y = 0};
{ x = centre+(hwidth + 20); y = top + height - 15};
{ x = centre+(hwidth + 05); y = top + height + 05};
{ x = centre-(hwidth + 05); y = top + height + 05};
{ x = centre-(hwidth + 20); y = top + height - 15};
}
end[/lua] works fine.
Why?

Perhaps to due inconsistencies? In the bottom, you only use semicolons, while in the top in the parts that don’t work you use a mix of semicolons and commas.

Namely these lines:
[lua]
{ x = width + 20, y = top };
{ x = width, y = top+height };
{ x = 0, y = top+height };
[/lua]

Syntactically they are the same so it shouldn’t matter.
I will test.

[editline]11:32PM[/editline]

Didn’t help.


local top = ScrH() - top

Wouldn’t that eventually make top go all screwy? i.e. let’s say ScrH() = 1000

top = 200
top = 1000 - 200 = 800
top = 1000 - 800 = 200

It would vary values really fast.

Nope, because of scope. As soon as the function ends, it goes back to being 200.

[editline]11:54PM[/editline]


Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> do
>> local top = 200
>> local tap = 200
>> for i = 1, 10 do
>>      local top = 1000 - top
>>      tap = 1000 - tap
>>      print(top,tap)
>> end
>> end
800     800
800     200
800     800
800     200
800     800
800     200
800     800
800     200
800     800
800     200
>

Ah, right. Darn scope.
As for your problem… that’s weird.
If you put the same poly functions in PaintCompass do they work?

…They both do. What the fuck?

[editline]12:09AM[/editline]

…Aaand surface.SetTexture() after setting the colour fixed it.
Thanks for that. It alerted me to the fact that the draw functions fuck with the surface texture. :3:

Yeah, I ran into this problem when I was trying to draw an untextured/generic poly across a series of panels, and only the first would draw followed by no others.

I fixed it like this:



draw.NoTexture( )
surface.DrawPoly( polyhere )


I think somewhere along the line, the texture reference in the surface library gets set to a transparent texture, given that I don’t get any strange textures where they shouldn’t be.

Although you found it out yourself, it is still worth mentioning.

draw.NoTexture() is surface.SetTexture( surface.GetTextureID( “vgui/white” ) ), but surface.SetTexture() alone seems to do the same thing.
draw.RoundedBox() sets the draw texture to “gui/corner8”, which apparently draws entirely transparent if you don’t set the texture points in surface.DrawPoly{}.
:3: