Skip to content

Instantly share code, notes, and snippets.

@meepen
Last active July 1, 2017 20:58
Show Gist options
  • Save meepen/447587d427553c0277d9cb09d4199258 to your computer and use it in GitHub Desktop.
Save meepen/447587d427553c0277d9cb09d4199258 to your computer and use it in GitHub Desktop.
Legendary old code from Meep Optimizer, previously unreleased code.
--If you want to use this file, go ahead! It's free to use! Include in any project!
-- All rights go back to their respective owner, MeepDarknessMeep (76561198050165746)
--[[-------------------------------------------------------------------
----opt.DrawStatic
----Things it does:
------Caches the HUD so that you don't render it every frame
------Thus, making it a lot faster.
----How to use:
------Call in an HUDPaint hook. Use only with static stuff
------such as backgrounds on boxes
-------------------------------------------------------------------]]--
opt.static_rts = opt.static_rts or {};
local static_mat = CreateMaterial("meepopt_statichud", "GMODScreenspace", {
["$translucent"] = 0,
["$alpha"] = 1,
["$texturealpha"] = 1,
["$vertexalpha"] = 0,
});
function opt.DrawStatic(name, fn, forcereload)
local rt = opt.static_rts[name];
if(not rt or forcereload) then
rt = GetRenderTarget("meepopt_"..tostring(name), ScrW(), ScrH(), false);
opt.static_rts[name] = rt;
local old_rt = render.GetRenderTarget();
render.SetRenderTarget(rt);
render.Clear(0,0,0,0, true, true);
render.OverrideAlphaWriteEnable(true, true);
fn();
render.OverrideAlphaWriteEnable(false);
render.SetRenderTarget(old_rt);
end
static_mat:SetTexture("$basetexture", rt);
render.SetMaterial(static_mat);
render.DrawScreenQuad();
return true;
end
local function drawer()
for h = 0, 360 do
for s = 0, 360 do
surface.SetDrawColor(HSVToColor(h, s / 360, 80)
surface.DrawRect(h + 100, s + 100, 1, 1)
end
end
end
hook.Add("HUDPaint", "test_hud_bs", function()
opt.DrawStatic("test_hud_bs_colors", drawer, false)
surface.SetTextColor(255,255,255)
surface.SetFont "BudgetLabel"
surface.SetTextPos(90, 90)
surface.DrawText(os.date("The time is %H:%m:%S"))
end)
Copyright (c) 2015-2017 Meepen / MeepDarknessMeep
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment