Skip to content

Instantly share code, notes, and snippets.

@x4fx77x4f
Last active October 22, 2020 02:03
Show Gist options
  • Save x4fx77x4f/495ad74f9db3180fec02739a3c6dcb05 to your computer and use it in GitHub Desktop.
Save x4fx77x4f/495ad74f9db3180fec02739a3c6dcb05 to your computer and use it in GitHub Desktop.
Render .lmp texture files from Quake 1 in StarfallEx
--@name Quake LMP renderer
--@client
local p = file.read("quakefall/gfx/palette.lmp")
local d = file.read("quakefall/gfx/mainmenu.lmp")
d = bit.stringstream(d)
local threshold = quotaMax()*0.7
local function yield(rt)
if math.max(quotaUsed(), quotaAverage()) >= threshold then
coroutine.yield()
if rt then
render.selectRenderTarget(rt)
end
end
end
local x, y, w, h, u1, v1, u2, v2 = 0, 0, 512, 512, 0, 0, 1, 1
local thread = coroutine.create(function()
render.createRenderTarget("main")
render.selectRenderTarget("main")
local iw = d:readUInt32()-1
local ih = d:readUInt32()-1
u2 = iw/1024
v2 = ih/1024
if iw ~= ih then
local maxd = iw > ih and iw or ih
local mind = iw < ih and iw or ih
local aspect = mind/maxd
if maxd == iw then
local oh = h
h = oh*aspect
y = (oh-h)/2
else
local ow = w
w = ow*aspect
x = (ow-w)/2
end
end
for y=0, ih do
for x=0, iw do
local i = d:read(1)
if i ~= "\xff" then
local j = i:byte()*3+1
local r = p:sub(j, j):byte()
local g = p:sub(j+1, j+1):byte()
local b = p:sub(j+2, j+2):byte()
render.setRGBA(r, g, b, 255)
render.drawRect(x, y, 1, 1)
end
end
yield("main")
end
end)
hook.add("render", "render", function()
render.setFilterMag(1)
render.setFilterMin(1)
if coroutine.status(thread) ~= "dead" and math.max(quotaUsed(), quotaAverage()) < threshold then
coroutine.resume(thread)
end
render.setRGBA(255, 255, 255, 255)
render.selectRenderTarget()
render.setRenderTargetTexture("main")
render.drawTexturedRectUV(x, y, w, h, u1, v1, u2, v2)
end)
@x4fx77x4f
Copy link
Author

Screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment