Hey!
I managed to stop the game from crashing with this code by removing the if not status then error and now I just get white from the HTML material:
[thumb]http://i.imgur.com/IRNO6D7.jpg[/thumb]
Heres the code:
[CODE]
local pos = Vector(0, 0, 0)
local ang = Angle(0, 270, 90)
local width = 1024
local height = 768
local scale = 0.125
local url = "http://google.com"
if g_3DHTML and g_3DHTML:IsValid() then g_3DHTML:Remove() end
local browser = vgui.Create("HTML")
g_3DHTML = browser
browser:SetPaintedManually(true)
browser:SetSize(width, height)
browser:SetMouseInputEnabled(false)
browser:OpenURL(url)
local function DrawSign()
-- Draw a background
surface.SetDrawColor(255, 255, 255, 255)
surface.DrawRect(0, 0, width, height)
-- Draw the screen
render.SetMaterial(browser:GetHTMLMaterial())
render.DrawQuad(Vector(0, 0, 0),
Vector(width, 0, 0),
Vector(width, height, 0),
Vector(10, height, 0))
end
hook.Add("RenderScreenspaceEffects", "3DHTMLSign", function()
cam.Start3D(EyePos(), EyeAngles())
cam.Start3D2D(pos, ang, scale)
local status, err = pcall(DrawSign)
cam.End3D2D()
end)
[/CODE]
I have heard Awesominium is broken on Mac and I heard thats what it uses to display HTML so maybe that might be it?
You need to call Panel.UpdateHTMLTexture before calling Panel.GetHTMLMaterial. Also, the material returned likely won't be the size of the panel as it's scaled up to the the closest power of two. Here's some code I used in the Cinema gamemode:
[code]local math = math
local surface = surface
local ValidPanel = ValidPanel
function math.CeilPower2(n)
return math.pow(2, math.ceil(math.log(n) / math.log(2)))
end
function draw.HTMLTexture( panel, w, h )
if not ( panel and ValidPanel(panel) and w and h ) then return end
panel:UpdateHTMLTexture()
local pw, ph = panel:GetSize()
-- Convert to scalar
w = w / pw
h = h / ph
-- Fix for non-power-of-two html panel size
pw = math.CeilPower2(pw)
ph = math.CeilPower2(ph)
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( panel:GetHTMLMaterial() )
surface.DrawTexturedRect( 0, 0, w * pw, h * ph )
end[/code]
Ahhh awesome!
Youl have to forgive my ignorance but how would I go about executing that? Would I change the hooks function to the draw.HTMLTexture? And where abouts in my current code would I put that? Again, really sorry for this dumb question. Im very new to how LUA works xD
Pass the HTML panel, width, and height to draw.HTMLTexture.
[code]draw.HTMLTexture( browser, width, height )[/code]
Ahh right cool.
Still having the same problem and this is what I've got now:
[code]
local pos = Vector(0, 0, 0)
local ang = Angle(0, 270, 90)
local width = 1024
local height = 768
local scale = 0.125
local url = "http://google.com"
if g_3DHTML and g_3DHTML:IsValid() then g_3DHTML:Remove() end
local browser = vgui.Create("HTML")
g_3DHTML = browser
browser:SetPaintedManually(true)
browser:SetSize(width, height)
browser:SetMouseInputEnabled(false)
browser:OpenURL(url)
local function DrawSign()
-- Draw a background
surface.SetDrawColor(255, 255, 255, 255)
surface.DrawRect(0, 0, width, height)
-- Draw the screen
render.SetMaterial(browser:GetHTMLMaterial())
render.DrawQuad(Vector(0, 0, 0),
Vector(width, 0, 0),
Vector(width, height, 0),
Vector(10, height, 0))
draw.HTMLTexture( browser, width, height )
end
local math = math
local surface = surface
local ValidPanel = ValidPanel
function math.CeilPower2(n)
return math.pow(2, math.ceil(math.log(n) / math.log(2)))
end
function draw.HTMLTexture( panel, w, h )
if not ( panel and ValidPanel(panel) and w and h ) then return end
panel:UpdateHTMLTexture()
local pw, ph = panel:GetSize()
-- Convert to scalar
w = w / pw
h = h / ph
-- Fix for non-power-of-two html panel size
pw = math.CeilPower2(pw)
ph = math.CeilPower2(ph)
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( panel:GetHTMLMaterial() )
surface.DrawTexturedRect( 0, 0, w * pw, h * ph )
draw.HTMLTexture( browser, width, height )
end
hook.Add("RenderScreenspaceEffects", "3DHTMLSign", function()
cam.Start3D(EyePos(), EyeAngles())
cam.Start3D2D(pos, ang, scale)
local status, err = pcall(DrawSign)
cam.End3D2D()
end)
[/code]
Sorry, you need to Log In to post a reply to this thread.