Displaying an image from URL using 3d2d

I had no luck asking in the “Problems that don’t need their own thread”, so maybe someone could see it here and have an answer.
I’d like to load an image on a board entity, using 3d2d. Besides using this, are there any alternatives available?

Load it in to a (D)HTML panel, run GetHTMLMaterial.

It might be good to throw it on a RT and make your own though.

That means i’d have to use https://github.com/HandsomeMatt/3d2d-vgui, no?

No. You just do something like this:



-- pHtml is your HTML element
cam.Start3D2D(pos, ang, 0.02)
    surface.SetDrawColor(color_white)
    surface.SetMaterial(pHtml:GetHTMLMaterial())
    surface.DrawTexturedRect(-256, -256, 512, 512)
cam.End3D2D()


I created my panel inside cl_init.lua (not inside any function), and afterwards I did that in ENT:Draw(), but the material is always nil.

In draw check this,

if IsValid(pHtml) and pHtml:GetHTMLMaterial() then

Thats like just checking it is loaded.

I have done that, and it never loads. As I said it’s always nil.

Post your code?

Make sure your panel isn’t a local object.

Edit: Why are you trying to use a html panel to load an image anyways? If you’re trying to have clients load new images without having to use resource.AddFile, you might want to consider using the WriteData and Material functions to send and load the image, assuming it’s not a really massive file. Awesomium HTML panels can be pretty expensive on the client if you’re using several of them.

GetHTMLMaterial creates a material every frame, i’d not call it 24/7

Well it doesn’t work anyways.



include("shared.lua")


pnlHTML = vgui.Create("HTML")
pnlHTML:SetVisible(true)
--pnlHTML:SetPos(50,50)
pnlHTML:SetPos(ScrW()-1, ScrH()-1)
pnlHTML:SetSize(size, size)
pnlHTML:SetHTML(
	[[
		<img src="http://vignette2.wikia.nocookie.net/thestanleyparable/images/0/04/Facepunchoc5.png/revision/latest?cb=20131019161144" alt="Test" style="width:256px;height:256px;">
	]]
)


function ENT:Draw()
	self:DrawModel()
	local DrawPos = self:LocalToWorld(Vector(1, -111, 58))
	local DrawAngles = self:GetAngles()
	DrawAngles:RotateAroundAxis(self:GetAngles():Forward(), 90)
	DrawAngles:RotateAroundAxis(self:GetAngles():Up(), 90)

	cam.Start3D2D(DrawPos, DrawAngles, 0.4)
	    surface.SetDrawColor(color_white)
	    if pnlHTML:GetHTMLMaterial() then 
			surface.SetMaterial(pnlHTML:GetHTMLMaterial())
	  	end
		surface.DrawTexturedRect(0, 0, 558, 290)
	cam.End3D2D()
end


[editline]8th August 2015[/editline]

Tried this aswell:



include("shared.lua")

net.Receive( "ImageSet", function( len )
	local IMAGE_URL = net.ReadString()
	local pnlHTML = vgui.Create("HTML")
	pnlHTML:SetVisible(true)
	--pnlHTML:SetPos(50,50)
	pnlHTML:SetPos(ScrW()-1, ScrH()-1)
	pnlHTML:SetSize(size, size)
	pnlHTML:SetHTML(
		[[
			<img src="]]..IMAGE_URL..[[" alt="Test" style="width:256px;height:256px;">
		]]
	)
	timer.Simple(5, function() 
		if pnlHTML:GetHTMLMaterial() then 
				mat_url_image = pnlHTML:GetHTMLMaterial()
		end
	end)
end )

function ENT:Draw()
	self:DrawModel()
	local DrawPos = self:LocalToWorld(Vector(1, -111, 58))
	local DrawAngles = self:GetAngles()
	DrawAngles:RotateAroundAxis(self:GetAngles():Forward(), 90)
	DrawAngles:RotateAroundAxis(self:GetAngles():Up(), 90)

	cam.Start3D2D(DrawPos, DrawAngles, 0.4)
		if mat_url_image then 
			surface.SetMaterial(mat_url_image)
		end
		surface.DrawTexturedRect(0, 0, 558, 290)
	cam.End3D2D()
end


ImageSet is used whenever the pic is changing.

Just take the easy way out and have the image be downloaded as a material.

Here’s the interface for a module I created to handle downloading web materials and pooling browser instances:
[lua]—
– Renders a URL as a material. Texture will be updated every time the material
– is requested until the image finishes downloading.

@param url URL.
@param style HTMLMaterial style (optional).
@return Material

function HTMLMaterial( url, style )

– ‘style’ parameter accepts registered HTML material style keys. Preregistered
– keys include the following globals:
HTMLMAT_STYLE_BLUR
HTMLMAT_STYLE_GRAYSCALE
HTMLMAT_STYLE_SEPIA
HTMLMAT_STYLE_INVERT
HTMLMAT_STYLE_CIRCLE

– See ‘AddHTMLMaterialStyle’ for registering new styles[/lua]

Dependencies: dmediaplayerhtml.lua, browserpool.lua, and htmlmaterial.lua.