Skip to content

Instantly share code, notes, and snippets.

@Codingale
Forked from mattkrins/cl_surfaceGetURL.lua
Last active October 15, 2019 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Codingale/69c9be291531125c23d891fb15366c56 to your computer and use it in GitHub Desktop.
Save Codingale/69c9be291531125c23d891fb15366c56 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 not url or not w or not 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 not 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment