Images in HUD


  • I am adding a HUD via creating a module in darkrpmofications

  • I’d like to put an icon I have made via photoshop (it’s a .png file) in the hud, to represent health it’s called health-icon.png

  • I understand how to sync it to FastDL and get it to download via joining, however how would I actually implement it into a HUD using darkrpmodifications modules.

I tried the following but it seems to appear as pink&black squares:

surface.DrawTexturedRect(ScrW() - 220,ScrH() / 1.6,32,32)

Could anybody help me fix this so that I have a healthy icon ingame ;D

When you are using a png, you need to tell the engine to use the .png instead of looking for a normal material.

Since you are using the png, you should also take advantage of what you can do with the creation options by specifying smooth and mips so it looks nicer - png textures can get a bit fuzzy around the edges if you don’t specify one or both.
So, do something like this instead:

--Outside your drawing function
local mat = Material( "wcservercustom/hud/health-icon.png", "smooth mips" )

--Inside your drawing function
surface.SetMaterial( mat )
surface.DrawTextureRect( ... )

This has definitely helped, however I now can see the image ingame however it is rather dark for some reason, a lot darker than the png file is, as well as it has some pinky/red lines around it.

Anything I could of done wrong to cause this, or how could I prevent it from going dark with red/pinky outlines


Png file

[editline]6th August 2015[/editline]

Found the issue making the icons darker, I removed the box I had behind the icons and now they have disappeared? Help?

Before drawing your image do this:


Ah thanks, if anybody could possibly assist with one more thing:

I have uploaded my materials to my garrysmod directory, being materials/wcserverscutom/hud/health-icon.png

I then synced fastdl and it synced it, being on fastdl.

I also made a folder named wcserverscustom.lua in garrysmod/lua/autorun/

Within this file is the folowing:


Why is nobody able to see the icons ingame still?

Use resource.AddSingleFile for PNG files.