Drawing a custom texture for a HUD?

Hello FPers,

I am relatively new to LUA scripting and for my first project, I am wanting to make a custom HUD that utilizes textures that a friend and I have made. The problem is that I am not sure how to go about drawing the textures on the player’s screen. I know how to hide the default HL2 HUD and draw simple text with no problem, just not custom textures.

Anyone with any knowledge that can help me go about doing this is deeply appreciated. Thank you again!

Do you mean like drawing up a HUD in photoshop and sticking it on your screen? If so its like this:

surface.SetMaterial( Material( "path/to/file.png" ) )
surface.DrawTexturedRect( x, y, width, height )

If you’re using a .png file you would use whats above, but if you plan on using a vtf/vmt you would need to save the file as a .tga and convert it via VTFEdit and set the path to the file but without the .vmt ending so it would look like “path/to/file”

Also check out the following links for more information on the surface library.
VTFEdit (if you dont have it)

-- This line is supposed to be somewhere OUTSIDE of drawing hooks, so it is ran only once
local mat = Material("path/to/texture.png") -- Will load materials/path/to/texture.png
local mat2 = Material("path/to/texture") -- Will load materials/path/to/texture.vmt

surface.SetDrawColor(color_white) -- color_white = Color(255,255,255) by default
surface.SetMaterial( mat )
surface.DrawRect( 25, 25, 100, 100 ) -- X: 25, Y: 25, Width and Height: 100

Just make sure the Material( ) is called outside of any loops / HUDPaint / etc… Call it and store it as a variable, then use it within otherwise you may run out of memory / crash.

edit: ninja’d

@ _Jacob: All custom textures that me and my friend had created were saved as .pngs and converted into .vtfs and .vmts. Thank you for the bits of info!

@ Robotboy655 and Acecool: Excellent, this is very useful. I’ll try these out and inform you both with the results in this thread. I will have to do it tomorrow since it’s rather late here.

Thank you all for the quick replies, I really appreciate all of the help!