Skip to content

Instantly share code, notes, and snippets.

@mattkrins
Last active December 1, 2022 18:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mattkrins/5455b96631cc2ebdf0e577a71d1a3d54 to your computer and use it in GitHub Desktop.
Save mattkrins/5455b96631cc2ebdf0e577a71d1a3d54 to your computer and use it in GitHub Desktop.
This is a simple Garry's Mod helper function to hot-load images from a web URL for use in your rendering operations.
local WebMaterials = {}
function surface.GetURL(url, w, h, time)
if !url or !w or !h then return Material("error") end
if WebMaterials[url] then return WebMaterials[url] end
local WebPanel = vgui.Create( "HTML" )
WebPanel:SetAlpha( 0 )
WebPanel:SetSize( tonumber(w), tonumber(h) )
WebPanel:OpenURL( url )
WebPanel.Paint = function(self)
if !WebMaterials[url] and self:GetHTMLMaterial() then
WebMaterials[url] = self:GetHTMLMaterial()
self:Remove()
end
end
timer.Simple( 1 or tonumber(time), function() if IsValid(WebPanel) then WebPanel:Remove() end end ) // In case we do not render
return Material("error")
end
@garryspins
Copy link

cache the error material
and dont use HTML for this, use an http fetch request and put the body in a file, then use Material("../data/image.png") or whatever

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment