 # Materials spaz out when used with surface.DrawPoly.

Could someone inform me on what I’m doing wrong? I’ve created a 32x32 plain white vtf/vmt image that I want to use for the background of a surface.DrawPoly. Although when I look at it in game, it will spaz between the colors white grey and black in a million different lines and flickering patterns.

https://dl.dropboxusercontent.com/u/30778198/trian.png

Image: https://dl.dropboxusercontent.com/u/30778198/trian.png
I’m using the example code from the wiki for a triangle as well.
[lua]
triangletex = surface.GetTextureID(“hud_display/white_block”) – this is our triangles texture, try to find your own
centerx = ScrW()/2 --this is the middle x cordinate
centery = ScrH()/2 --this is the middle y cordinate
trianglevertex = {{ },{ },{ }} --create the two dimensional table

–First Vertex
trianglevertex[“x”] = centerx
trianglevertex[“y”] = centery
trianglevertex[“u”] = 0 //Top Left
trianglevertex[“v”] = 0

–Second Vertex
trianglevertex[“x”] = centerx + 50
trianglevertex[“y”] = centery
trianglevertex[“u”] = 1 //Top Right
trianglevertex[“v”] = 0

–Third Vertex
trianglevertex[“x”] = centerx
trianglevertex[“y”] = centery + 50
trianglevertex[“u”] = 0 //Bottom Left
trianglevertex[“v”] = 1

HUD_DISPLAY.HUD = function()

``````surface.SetTexture( triangletex ) --set the texture of the triangle
surface.SetDrawColor( 255, 255, 255, 255 ) --set the additive color
surface.DrawPoly( trianglevertex ) --draw the triangle with our triangle table
``````

end
[/lua]

You should use my triangle example.
[lua]
if SERVER then
else
function surface.DrawFilledTriangle(ax, ay, bx, by, cx, cy, col)
local triangle = {
{x = ax, y = ay},
{x = bx, y = by},
{x = cx, y = cy}
}
surface.SetDrawColor(col)
surface.DrawPoly(triangle)
end

``````hook.Add("HUDPaint", "SurfaceTriangle", function()
surface.DrawFilledTriangle(100, 100, 50, 150, 150, 150, Color(255,255,255,255))
end)
``````

end
[/lua]

http://puu.sh/2UdN5.jpg

Also, make sure that the vmt type is an UnlitGeneric.

How would I make it UnlitGeneric, I don’t see a flag for that and I’m new to making materials and using this vtf editor? Also is that what is causing the issue for my flickering image? As well I switched to the code you’ve given me, thanks.

You should see this when you go to your VTF edit.

http://puu.sh/2UGKw.png

Then when you’re making the VMT file.

http://puu.sh/2UGIb.png

An alternative would be to just open your VMT with VTF edit and just edit the top part here:

to

Ok cool I got it working! Thanks for the help.