• Custom VGUI materials?
    17 replies, posted
I want to add a silkicon in my menu. The icon is located in <gamemode>/content/materials/vgui/silkicons/test.png This is my code for it to show. [lua] surface.SetDrawColor(255,255,255) surface.SetTexture(surface.GetTextureID("vgui/silkicons/test.png")) surface.DrawTexturedRect(90,35,32,32) [/lua] But in-game its a purple-black textured box. I think I miss a line of code for it to work, but after looking around on the wiki I haven't found any answers that would help me. My clientside console gets spammed with this missing texture error. [quote] --- Missing Vgui material vgui/silkicons/test.png --- Missing Vgui material vgui/silkicons/test.png --- Missing Vgui material vgui/silkicons/test.png [/quote] Hopefully I can get this to work, I planned on using this a lot once I get the hang of it.
[code]--Example 1: surface.SetDrawColor(255,255,255) surface.SetMaterial( Material( "icon16/coins.png" ) ) --Use dir icon16/ for silkicons surface.DrawTexturedRect(90,35,32,32) --Example 2: local alert_img = Material("icon16/alert") -- use a local variable designated somewhere else above in the same file surface.SetDrawColor(255,255,255) surface.SetMaterial( alert_img ) surface.DrawTexturedRect(90,35,32,32) [/code] When using png's/vmt's with surface.DrawTexturedRect() use Material() to get your image, it takes out the need to include the /materials/ directory. For future reference you don't have to include the image extension either, although you can of course. I'm not entirely sure the difference between Set/Get Texture and Set Material are, but I've only ever used Material. Also icon16 png's are 16x16 so blowing them up bigger than about 24x24 looks really bad.
The console error has disappeared, however the texture is still missing in-game. This is not one of the default 16x16 icons, so I might need to add something to it, but I still haven't found what it is. [lua] surface.SetDrawColor(255,255,255) surface.SetMaterial( Material( "vgui/silkicons/test.png" ) ) surface.DrawTexturedRect(90,35,32,32) [/lua]
Have you fastdl'd/actually got the picture?
Yes the picture is in <gamemode>/content/materials/vgui/silkicons/test.png, and the server is local, so there shouldn't be any issue with getting it.
You do realize that every single silkicon is shipped with GMod by default?
But its not one of the default icons. I guess that means I should put it in a different folder (?)
[QUOTE=Skere_;49109035]But its not one of the default icons. I guess that means I should put it in a different folder (?)[/QUOTE] No. The files from <gamemode>/content/materials/vgui/silkicons/test.png will only load if the current gamemode Is the <gamemode>. ( I.E. You can't use those files in sandbox )
[QUOTE=Robotboy655;49109140]No. The files from <gamemode>/content/materials/vgui/silkicons/test.png will only load if the current gamemode Is the <gamemode>. ( I.E. You can't use those files in sandbox )[/QUOTE] I will only use them in this gamemode anyway, but that still doesn't explain why they don't load.
Does it work if you put the .png into [b]common/GarrysMod/garrysmod/materials/vgui/silkicons/test.png[/b]?
[QUOTE=Robotboy655;49110244]Does it work if you put the .png into [b]common/GarrysMod/garrysmod/materials/vgui/silkicons/test.png[/b]?[/QUOTE] Nope, no different results on that sadly
Alright, you are clearly doing something wrong. Can you post a screenshot of the file's location ( so that the full path to the file is visible, as well the file itself ) Are you testing this in single player on your own gamemode? Is it a server?
Its a local dedicated server. Its on my pc but it is portforwarded (so it uses a start.bat) [img]http://i.imgur.com/elFJ0RD.png[/img] Couldn't show the path in code, so I'll leave it here. C:\gmod\garrysmod\gamemodes\skeretdm\content\materials\vgui\silkicons
[QUOTE=Robotboy655;49108134]You do realize that every single silkicon is shipped with GMod by default?[/QUOTE] Sorry for a pointless post, but last time I checked, the icon 'disk_multiple.png' was a missing file
Alright, so the file obviously is not on your GMOD CLIENT, as in, it exists on your server, but it is not sent to your Garry's Mod client, which ultimately displays the file. In a serverside file, use resource.AddFile() with the relative filepath to the icon to send the icon from the server to your client(s). See wiki page for the function for more details. Also it's worth mentioning that you are do not HAVE to use the vgui/silkicons/ folder for your icons and stuff, you can just use something like materials/<uniquesevername>/myicon.png so that there's no chance another server might use a different file with the same file path, creating conflicts. [editline]14th November 2015[/editline] [QUOTE=MPan1;49111349]Sorry for a pointless post, but last time I checked, the icon 'disk_multiple.png' was a missing file[/QUOTE] Right you are, there are in fact 6 missing icons, will be taken care of, disk_multiple.png is not one of those missing icons though.
I added this to garrysmod/gamemodes/skeretdm/gamemode/init.lua The folder is changed to nicename (just temporarily) Its full path is now C:\gmod\garrysmod\gamemodes\skeretdm\content\materials\vgui\nicename\test.png According to the wiki, you only have to add the path after the materials/ [lua]resource.AddFile("nicename/test.png")[/lua] This might be good to know; After doing some testing, even if I change the resource.Add or setmaterial to inexisting stuff, I still don't find any errors in both the in-game console and server console.
Please read the wiki page, it states that you must include the relative to garrysmod/ folder path.
[QUOTE=Robotboy655;49111850]Please read the wiki page, it states that you must include the relative to garrysmod/ folder path.[/QUOTE] Please excuse me for my blindness, and thanks a lot for your time, it worked out!
Sorry, you need to Log In to post a reply to this thread.