• How to load image data as an IMaterial?
    3 replies, posted
I'm not sure if this question needs it's own thread, but here's what I want to know: Is it possible to load image data (such as the string generated by [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/render/Capture]render.Capture[/url]) as an IMaterial without having to save the image data and then load it again? Currently I have to do this: [CODE] local data = render.Capture( { format = "jpeg", quality = 100, h = ScrH(), w = ScrW(), x = 0, y = 0, } ) file.Write( 'lol.jpg', data ) RunConsoleCommand( 'mat_reloadmaterial', 'data/lol' ) local mat = Material( 'data/lol.jpg' ) [/CODE] But it's very slow to run and it seems a bit stupid... I'd like to simply do something like [CODE] local data = render.Capture( { format = "jpeg", quality = 100, h = ScrH(), w = ScrW(), x = 0, y = 0, } ) local mat = Material( data ) [/CODE] But that doesn't work since Garry's Mod always likes making things unnecessarily complicated Also, it needs to be an IMaterial because I'm using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/surface/SetMaterial]surface.SetMaterial[/url] to draw a textured rect with the material Any help would be appreciated!
Sometimes you just have to make one giant ugly hack to get simple things don. I'm even unsure if I should release my clothes-addon based on how ugly the code is. I guess the "easiest" and best way, is to use a html-page to render the texture. Something like BlackAwps solution. [QUOTE=BlackAwps;40691671]It works fine for me without a hook. [lua]concommand.Add( "bp_map_icon", function( ply, cmd, args, raw ) render.RenderView( { angles = EyeAngles(), origin = EyePos(), x = 0, y = 0, w = 128, h = 128, drawhud = false, drawviewmodel = false, aspectratio = 1, fov = 70, } ) local data = render.Capture( { format = "jpeg", quality = 100, x = 0, y = 0, w = 128, h = 128, } ) data = util.Base64Encode( data ) local frame = vgui.Create( "DFrame" ) frame:SetTitle( "Icon" ) frame:SetSize( 128 + 10, 128 + 31 + 26 ) frame:Center() frame:MakePopup() local html = frame:Add( "HTML" ) html:SetHTML( [[ <style type="text/css"> body { margin: 0; padding: 0; overflow: hidden; } img { width: 100%; height: 100%; } </style> <img src="data:image/jpg;base64,]] .. data .. [["> ]] ) html:Dock( FILL ) local upload = frame:Add( "DButton" ) upload:SetHeight( 26 ) upload:SetText( "Upload" ) upload:Dock( BOTTOM ) function upload:DoClick() net.Start( "BPMapIcon" ) net.WriteString( data ) net.SendToServer() print( "Sent image data to the server, verifying.." ) end end )[/lua][/QUOTE]
IMaterial cannot contain texture data, so obviously you cannot give it texture data. IMaterial represents .vmt file, ITexture represents .vtf
[QUOTE=Robotboy655;50192578]IMaterial cannot contain texture data, so obviously you cannot give it texture data. IMaterial represents .vmt file, ITexture represents .vtf[/QUOTE] So are you saying it's possible with an ITexture?
Sorry, you need to Log In to post a reply to this thread.