• Set Image URL?
    12 replies, posted
Anyone know how to set a panels texture/material to a URL image? I've seen it before but lost as to how people do it.
I created a library for getting a material from a URL: [URL="https://github.com/pixeltailgames/gm-mediaplayer/blob/master/lua/autorun/includes/modules/htmlmaterial.lua"]htmlmaterial.lua[/URL] which depends on [URL="https://github.com/pixeltailgames/gm-mediaplayer/blob/master/lua/autorun/includes/modules/browserpool.lua"]browserpool.lua[/URL] and [URL="https://github.com/pixeltailgames/gm-mediaplayer/blob/master/lua/mediaplayer/controls/dmediaplayerhtml.lua"]an extended DHTML derma control[/URL]. Usage: [lua]local mat = HTMLMaterial( "https://example.com/example.png" )[/lua]
[QUOTE=samm5506;47160688]I created a library for getting a material from a URL: [URL="https://github.com/pixeltailgames/gm-mediaplayer/blob/master/lua/autorun/includes/modules/htmlmaterial.lua"]htmlmaterial.lua[/URL] which depends on [URL="https://github.com/pixeltailgames/gm-mediaplayer/blob/master/lua/autorun/includes/modules/browserpool.lua"]browserpool.lua[/URL]. Usage: [lua]local mat = HTMLMaterial( "https://example.com/example.png" )[/lua][/QUOTE] Thanks but is there no simpler way to do it? I mean just a default Gmod function or something preferably less lines of code.
[QUOTE='[CLRP]extra;47160726']Thanks but is there no simpler way to do it? I mean just a default Gmod function or something preferably less lines of code.[/QUOTE] The only way I'm aware of doing it is by creating an Awesomium context and grabbing the painted texture.
[QUOTE=samm5506;47160754]The only way I'm aware of doing it is by creating an Awesomium context and grabbing the painted texture.[/QUOTE] I tried your html material module and for some reason it spams the console with errors: "attempt to call gloabal 'HTMLMaterial' (a nil value)"
I added an extra dependency to the original post, make sure you have each of them included.
[QUOTE=samm5506;47160790]I added an extra dependency to the original post, make sure you have each of them included.[/QUOTE] Hmm, everything you mentioned added and I still get the error. This the right usage? [code] HTMLTest.Paint = function() local ourMat = HTMLMaterial("https://celadorsanitario.files.wordpress.com/2011/11/aptitude_test1.gif") surface.SetDrawColor( 255, 255, 255, 255 ) surface.SetMaterial( ourMat ) -- If you use Material, cache it! surface.DrawTexturedRect( 0, 0, HTMLTest:GetWide(), HTMLTest:GetTall() ) end [/code]
Yes, it sounds like you didn't set the files to be downloaded on the client though. [lua]-- Must include these somewhere if SERVER then AddCSLuaFile("dmediaplayerhtml.lua") AddCSLuaFile("browserpool.lua") AddCSLuaFile("htmlmaterial.lua") else include("dmediaplayerhtml.lua") include("browserpool.lua") include("htmlmaterial.lua") end -- btw, PANEL.Paint passes in width and height HTML.Paint = function(self, width, height) -- ... end[/lua]
[QUOTE=samm5506;47160868]Yes, it sounds like you didn't set the files to be downloaded on the client though. [lua]-- Must include these somewhere if SERVER then AddCSLuaFile("dmediaplayerhtml.lua") AddCSLuaFile("browserpool.lua") AddCSLuaFile("htmlmaterial.lua") else include("dmediaplayerhtml.lua") include("browserpool.lua") include("htmlmaterial.lua") end -- btw, PANEL.Paint passes in width and height HTML.Paint = function(self, width, height) -- ... end[/lua][/QUOTE] Made a module that included them, still get errors. Im guessing im just being plain stupid here but please correct me if i've done it wrong. It also posts an error saying: attempt to index global 'derma' (a nil value) [code] derma.DefineControl( "DMediaPlayerHTML", "", PANEL, "Awesomium" ) [/code]
Are you sure you're not including it on the server? It should always exist on the client. Post your module's code.
A file in modules thats simply: [code] if SERVER then AddCSLuaFile("dmediaplayerhtml.lua") AddCSLuaFile("browserpool.lua") AddCSLuaFile("htmlmaterial.lua") else include("dmediaplayerhtml.lua") include("browserpool.lua") include("htmlmaterial.lua") end [/code]
Maybe the files are getting included before Garry's Mod has finishing loading all of it's dependencies (derma lib)? You might want to try placing your files in an addon.
[QUOTE=samm5506;47160997]Maybe the files are getting included before Garry's Mod has finishing loading all of it's dependencies (derma lib)? You might want to try placing your files in an addon.[/QUOTE] It works fine with the gm media player addon in the addons folder. I'll just do it that way, thanks :)
Sorry, you need to Log In to post a reply to this thread.