HUD Missing Texture

I’m trying to get a texture to appear on my HUD, but it always comes up as a missing texture.

Here’s my code:


hook.Add("HUDPaint" , "HUD" , function()
	surface.SetDrawColor( 255, 255, 255, 255 )
	surface.SetTexture(surface.GetTextureID("vgui/sanic/bukicon.png"))
	surface.DrawTexturedRect( 0, 0, 512, 512 )
end )

The vgui folder is in the (gamemode name)/materials folder.

.png images are not compatible with that function.

It isn’t working, even with a vmt.

I double checked and it’s referring to the correct vtf as well.

I’ve had this problem before. I finally just gave up.

What’s strange is that it works with materials like models/wireframe.vmt

note: not sure if this will work. just trying something out, idk.

try to make a new txt file in the material/vgui/sanic/ folder(have the vtf file in there as well) add:



"UnlitGeneric"
{
	"$basetexture"		"vgui/sanic/bukicon"
	"$ignorez"		1
	"$vertexcolor"		1
	"$vertexalpha"		1
	"$nolod"			1
}


to it.

change the name to bukicon.vmt

also change surface.SetTexture(surface.GetTextureID(“vgui/sanic/bukicon.png”)) to surface.SetTexture(surface.GetTextureID(“vgui/sanic/bukicon.vmt”))

No avail :frowning:

Do not put an extension for GetTextureID

hmm?

[editline]26th April 2016[/editline]

Try this before you try my method.

My method isn’t proven to work.

Neither worked

[editline]26th April 2016[/editline]

I think I’m going to throw in the towel, this isn’t worth it

It’s your texture a vtf and do you have a png for this? Otherwise preload Material(path) and then for set texture just surface.SetMaterial()

I have a vtf and vmt

[editline]27th April 2016[/editline]

i have a png as well

Try

surface.SetMaterial instead (surface.SetTexture hardly ever works for me)

[editline]30th April 2016[/editline]

E.g.



local mat = Material("vgui/sanic/bukicon.png")

hook.Add("HUDPaint" , "HUD" , function()
	surface.SetDrawColor( 255, 255, 255, 255 )
	surface.SetMaterial( mat )
	surface.DrawTexturedRect( 0, 0, 512, 512 )
end )


Thats how I do it, although im not sure the filetype is necessary.

[editline]30th April 2016[/editline]
From the wiki under the drawtexturedrect:


local ourMat = Material( "models/wireframe" ) -- Calling Material() every frame is quite expensive

hook.Add( "HUDPaint", "example_hook", function()
    surface.SetDrawColor( 255, 255, 255, 255 )
    surface.SetMaterial( ourMat    ) -- If you use Material, cache it!
    surface.DrawTexturedRect( 0, 0, 512, 512 )
end )

You do need to have the filetype, the reason the one you posted didn’t have the filetype was because it was a .vmt file (they don’t need the extension)

Also, I updated my example so it caches the IMaterial before use

Still not working :what:

I’ve noticed its sometimes hard to see “/” in the material path name. Make sure you take a close look.


local mat = Material( "vgui/sanic/bukicon.png" )

hook.Add("HUDPaint" , "HUD" , function()
    surface.SetDrawColor( 255, 255, 255, 255 )
    surface.SetMaterial( mat )
    surface.DrawTexturedRect( 0, 0, 512, 512 )
end )

This is correct right?

Does it work?

Nope