Skip to content

Instantly share code, notes, and snippets.

@meepen
Last active February 22, 2021 17:40
Show Gist options
  • Save meepen/a2bb9c61e2cca03e2a37b2d305b1e0e0 to your computer and use it in GitHub Desktop.
Save meepen/a2bb9c61e2cca03e2a37b2d305b1e0e0 to your computer and use it in GitHub Desktop.

Revisions

  1. meepen revised this gist Apr 11, 2017. 1 changed file with 75 additions and 44 deletions.
    119 changes: 75 additions & 44 deletions non-powerof2-png-gmod.lua
    Original file line number Diff line number Diff line change
    @@ -1,56 +1,87 @@
    if IsValid(html) then
    html:Remove()
    end
    html = vgui.Create("DHTML")
    html:AddFunction("console", "memeify", function()
    local function wait_png(matstr)
    local html = vgui.Create("DHTML")
    html:AddFunction("console", "memeify", function()
    html.done = true
    end)
    local matstr = "luagb/images/5x3font_bm.png"
    local mat = Material(matstr)
    local rw, rh = mat:GetInt "$realwidth", mat:GetInt "$realheight"
    end)
    local mat = Material(matstr)
    local rw, rh = mat:GetInt "$realwidth", mat:GetInt "$realheight"

    local f = file.Open("materials/"..matstr, "rb", "GAME")
    local cont = f:Read(f:Size())
    f:Close()
    f = file.Open(matstr:gsub("/","_"), "wb", "DATA")
    f:Write(cont)
    f:Close()
    html:SetPos(ScrW() - 1, ScrH() - 1)
    local mapw, maph = 1, 1
    while (mapw < rw) do
    local f = file.Open("materials/"..matstr, "rb", "GAME")
    local cont = f:Read(f:Size())
    f:Close()
    f = file.Open(matstr:gsub("/","_"), "wb", "DATA")
    f:Write(cont)
    f:Close()
    html:SetPos(ScrW() - 1, ScrH() - 1)
    local mapw, maph = 1, 1
    while (mapw < rw) do
    mapw = mapw * 2
    end
    while (maph < rh) do
    end
    while (maph < rh) do
    maph = maph * 2
    end
    html:SetSize(mapw, maph)
    html:SetHTML([[
    end
    html:SetSize(mapw, maph)
    html:SetHTML([[
    <style>
    html {
    overflow:hidden;
    margin: -8px -8px;
    }
    html {
    overflow:hidden;
    margin: -8px -8px;
    }
    </style>
    <html>
    <img onload="console.memeify();" src="asset://garrysmod/data/]]..matstr:gsub("/","_")..[[" />
    <img onload="console.memeify();" src="asset://garrysmod/data/]]..matstr:gsub("/","_")..[[" />
    </html>
    ]])
    html:SetVisible(true)
    ]])
    html:SetVisible(true)

    transplant = transplant or CreateMaterial(math.random(), "UnlitGeneric", {
    ["$translucent"] = 1
    })
    hook.Add("Think", "testluagb", function()

    local co = love.__love_co
    local transplant = CreateMaterial("LoveEMU_"..rand.."transplant_png_"..png_count..matstr, "UnlitGeneric", {
    ["$translucent"] = 1,
    ["$nolod"] = 1,
    ["$ignorez"] = 1,
    ["$vertexalpha"] = 0,
    })
    png_count = png_count + 1
    love.__love_incallback = true

    local resume = function()
    love.__love_incallback = false
    love.__love_resume(co, transplant, rw, rh, mat)
    end

    hook.Add("Think", "LoveEMU_TransplantPNG", function()
    if (IsValid(html) and html.done and html:GetHTMLMaterial()) then
    local tex = html:GetHTMLMaterial():GetTexture "$basetexture"
    transplant:SetTexture("$basetexture", tex)
    tex:Download()
    html:Remove()
    hook.Add("HUDPaint","", function()
    surface.SetDrawColor(255,255,255,255)
    surface.SetMaterial(transplant)
    surface.DrawTexturedRect(0,0,mapw, maph)
    end)
    local tex = html:GetHTMLMaterial():GetTexture "$basetexture"
    transplant:SetTexture("$basetexture", tex)
    tex:Download()
    html:Remove()

    -- lol fuck memory we can't destroy or reuse it
    local rt = GetRenderTargetEx("LoveEMU_"..rand.."transplant_rt_"..png_count..matstr,
    mapw, maph, RT_SIZE_NO_CHANGE, MATERIAL_RT_DEPTH_NONE, 1, CREATERENDERTARGETFLAGS_UNFILTERABLE_OK, IMAGE_FORMAT_RGBA8888)
    render.PushRenderTarget(rt)
    render.OverrideAlphaWriteEnable(true, true)
    cam.Start2D()
    render.Clear(0, 0, 0, 0, false, false)
    surface.SetMaterial(transplant)
    surface.SetDrawColor(255,255,255,255)
    surface.DrawTexturedRectUV(0, 0, rw, rh, 0, 0, rw / mapw, rh / maph)
    render.OverrideAlphaWriteEnable(true, false)
    file.Write("loveemu_pot_"..matstr:gsub("/","_"), render.Capture {
    format = "png",
    alpha = true,
    x = 0,
    y = 0,
    w = mapw,
    h = maph
    })
    cam.End2D()
    mat = Material("data/loveemu_pot_"..matstr:gsub("/","_"), "noclamp")
    render.PopRenderTarget(rt)
    resume()
    end
    end)
    end)

    return love.__love_yield()
    end
  2. meepen created this gist Apr 11, 2017.
    56 changes: 56 additions & 0 deletions non-powerof2-png-gmod.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    if IsValid(html) then
    html:Remove()
    end
    html = vgui.Create("DHTML")
    html:AddFunction("console", "memeify", function()
    html.done = true
    end)
    local matstr = "luagb/images/5x3font_bm.png"
    local mat = Material(matstr)
    local rw, rh = mat:GetInt "$realwidth", mat:GetInt "$realheight"

    local f = file.Open("materials/"..matstr, "rb", "GAME")
    local cont = f:Read(f:Size())
    f:Close()
    f = file.Open(matstr:gsub("/","_"), "wb", "DATA")
    f:Write(cont)
    f:Close()
    html:SetPos(ScrW() - 1, ScrH() - 1)
    local mapw, maph = 1, 1
    while (mapw < rw) do
    mapw = mapw * 2
    end
    while (maph < rh) do
    maph = maph * 2
    end
    html:SetSize(mapw, maph)
    html:SetHTML([[
    <style>
    html {
    overflow:hidden;
    margin: -8px -8px;
    }
    </style>
    <html>
    <img onload="console.memeify();" src="asset://garrysmod/data/]]..matstr:gsub("/","_")..[[" />
    </html>
    ]])
    html:SetVisible(true)

    transplant = transplant or CreateMaterial(math.random(), "UnlitGeneric", {
    ["$translucent"] = 1
    })
    hook.Add("Think", "testluagb", function()
    if (IsValid(html) and html.done and html:GetHTMLMaterial()) then
    local tex = html:GetHTMLMaterial():GetTexture "$basetexture"
    transplant:SetTexture("$basetexture", tex)
    tex:Download()
    html:Remove()
    hook.Add("HUDPaint","", function()
    surface.SetDrawColor(255,255,255,255)
    surface.SetMaterial(transplant)
    surface.DrawTexturedRect(0,0,mapw, maph)
    end)

    end
    end)