Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 43 additions & 14 deletions lua/entities/gmod_wire_digitalscreen/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ local function stringToNumber(index, str, bytes)
return n, newpos
end

local pixelbits = {3, 1, 3, 4, 1}
local pixelbits = {3, 1, 3, 4, 1, 4}
net.Receive("wire_digitalscreen", function()
local ent = Entity(net.ReadUInt(16))

Expand Down Expand Up @@ -244,30 +244,39 @@ transformcolor[0] = function(c) -- RGBXXX
cg = cgray+28*math.fmod(math.floor(crgb / 10), 10)
cr = cgray+28*math.fmod(math.floor(crgb / 100), 10)

return cr, cg, cb
return cr, cg, cb, 255
end
transformcolor[2] = function(c) -- 24 bit mode
cb = math.fmod(c, 256)
cg = math.fmod(math.floor(c / 256), 256)
cr = math.fmod(math.floor(c / 65536), 256)

return cr, cg, cb
return cr, cg, cb, 255
end
transformcolor[3] = function(c) -- RRRGGGBBB
cb = math.fmod(c, 1000)
cg = math.fmod(math.floor(c / 1e3), 1000)
cr = math.fmod(math.floor(c / 1e6), 1000)

return cr, cg, cb
return cr, cg, cb, 255
end
transformcolor[4] = function(c) -- XXX
return c, c, c
return c, c, c, 255
end
transformcolor[5] = function(c) -- 32 bit mode
cb = math.fmod(c, 256)
cg = math.fmod(math.floor(c / 256), 256)
cr = math.fmod(math.floor(c / 65536), 256)
ca = math.fmod(math.floor(c / 16777216), 256)

return cr, cg, cb, ca
end

function ENT:RedrawPixel(a)
if a >= self.ScreenWidth*self.ScreenHeight then return end

local cr,cg,cb
local alpha = 255

local x = a % self.ScreenWidth
local y = math.floor(a / self.ScreenWidth)
Expand All @@ -280,12 +289,17 @@ function ENT:RedrawPixel(a)
cb = self.Memory1[a*3+2] or 0
else
local c = self.Memory1[a] or 0
cr, cg, cb = (transformcolor[colormode] or transformcolor[0])(c)
cr, cg, cb, alpha = (transformcolor[colormode] or transformcolor[0])(c)
end


surface.SetDrawColor(cr,cg,cb,255)
surface.DrawRect( x, y, 1, 1 )
if alpha ~= 255 then --save a step if transparency wouldnt matter
render.OverrideBlend(true, BLEND_ZERO, BLEND_ZERO, BLENDFUNC_ADD, BLEND_ZERO, BLEND_ZERO, BLENDFUNC_ADD)
surface.SetDrawColor(0, 0, 0, 255)
surface.DrawRect(x, y, 1, 1)
render.OverrideBlend(false)
end
surface.SetDrawColor(cr, cg, cb, alpha)
surface.DrawRect(x, y, 1, 1)
end

function ENT:RedrawRow(y)
Expand All @@ -294,20 +308,30 @@ function ENT:RedrawRow(y)

local colormode = self.Memory1[1048569] or 0

if colormode == 5 then
render.OverrideBlend(true, BLEND_ZERO, BLEND_ZERO, BLENDFUNC_ADD, BLEND_ZERO, BLEND_ZERO, BLENDFUNC_ADD)
surface.SetDrawColor(0, 0, 0, 255)
for x = 0,self.ScreenWidth-1 do
surface.DrawRect(x, y, 1, 1)
end
render.OverrideBlend(false)
end

for x = 0,self.ScreenWidth-1 do
local cr,cg,cb
local alpha = 255

if (colormode == 1) then
cr = self.Memory1[(a+x)*3 ] or 0
cg = self.Memory1[(a+x)*3+1] or 0
cb = self.Memory1[(a+x)*3+2] or 0
else
local c = self.Memory1[a+x] or 0
cr, cg, cb = (transformcolor[colormode] or transformcolor[0])(c)
cr, cg, cb, alpha = (transformcolor[colormode] or transformcolor[0])(c)
end

surface.SetDrawColor(cr,cg,cb,255)
surface.DrawRect( x, y, 1, 1 )
surface.SetDrawColor(cr, cg, cb, alpha)
surface.DrawRect(x, y, 1, 1)
end
end

Expand All @@ -326,8 +350,13 @@ function ENT:Draw(flags)
local idx = 0

if self.ClearQueued then
surface.SetDrawColor(0,0,0,255)
surface.DrawRect(0,0, 1024,1024)
local colormode = self.Memory1[1048569] or 0
if colormode == 5 then
render.ClearRenderTarget(self.GPU.RT, Color(0, 0, 0, 0)) --clear with alpha
else
surface.SetDrawColor(0, 0, 0, 255) --compatibility opaque clear
surface.DrawRect(0, 0, 1024, 1024)
end
self.ClearQueued = false
return
end
Expand Down
4 changes: 2 additions & 2 deletions lua/entities/gmod_wire_digitalscreen/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ end
util.AddNetworkString("wire_digitalscreen")


local pixelbits = {3, 1, 3, 4, 1} --The compressed pixel formats are in bytes
local pixelbits = {3, 1, 3, 4, 1, 4} --The compressed pixel formats are in bytes
function ENT:FlushCache(ply)
if not next(self.ChangedCellRanges) then
removeGlobalBW(self)
Expand Down Expand Up @@ -352,7 +352,7 @@ function ENT:WriteCell(Address, value)
end
else
if Address == 1048569 then
-- Color mode (0: RGBXXX; 1: R G B; 2: 24 bit RGB; 3: RRRGGGBBB; 4: XXX)
-- Color mode (0: RGBXXX; 1: R G B; 2: 24 bit RGB; 3: RRRGGGBBB; 4: XXX; 5: 32 bit RGBA)
value = math.Clamp(value, 0, 9)
elseif Address == 1048570 then -- Clear row
local row = math.Clamp(value, 0, self.ScreenHeight-1)
Expand Down
34 changes: 27 additions & 7 deletions lua/entities/gmod_wire_expression2/core/color.lua
Original file line number Diff line number Diff line change
Expand Up @@ -292,33 +292,53 @@ end
--- DIGI

local converters = {}
converters[0] = function(r, g, b)
converters[0] = function(r, g, b, a)
local r = Clamp(floor(r/28),0,9)
local g = Clamp(floor(g/28),0,9)
local b = Clamp(floor(b/28),0,9)

return r*100000+g*10000+b*1000
end
converters[1] = false
converters[2] = function(r, g, b)
converters[2] = function(r, g, b, a)
return floor(r)*65536+floor(g)*256+floor(b)
end
converters[3] = function(r, g, b)
converters[3] = function(r, g, b, a)
return floor(r)*1000000+floor(g)*1000+floor(b)
end
converters[4] = false
converters[5] = function(r, g, b, a)
return floor(a)*16777216+floor(r)*65536+floor(g)*256+floor(b)
end

--- Converts an RGB vector <rgb> to a number in digital screen format. <mode> Specifies a mode, either 0, 2 or 3, corresponding to Digital Screen color modes.
--- Converts an RGB vector <rgb> to a number in digital screen format. <mode> Specifies a mode, either 0, 2, 3 or 5 corresponding to Digital Screen color modes.
[nodiscard]
e2function number rgb2digi(vector rgb, mode)
local conv = converters[mode]
if not conv then return self:throw("Mode " .. mode .. " does not exist!", 0) end
return conv(rgb[1], rgb[2], rgb[3])
return conv(rgb[1], rgb[2], rgb[3], 255)
end

--- Converts the RGB color (<r>,<g>,<b>) to a number in digital screen format. <mode> Specifies a mode, either 0, 2 or 3, corresponding to Digital Screen color modes.
--- Converts the RGB color (<r>,<g>,<b>) to a number in digital screen format. <mode> Specifies a mode, either 0, 2, 3 or 5 corresponding to Digital Screen color modes.
[nodiscard]
e2function number rgb2digi(r, g, b, mode)
local conv = converters[mode]
if not conv then return self:throw("Mode " .. mode .. " does not exist!", 0) end
return conv(r, g, b)
return conv(r, g, b, 255)
end

--- Converts an RGBA vector4 <rgba> to a number in digital screen format. <mode> Specifies a mode, either 0, 2, 3 or 5 corresponding to Digital Screen color modes.
[nodiscard]
e2function number rgba2digi(vector4 rgb, mode)
local conv = converters[mode]
if not conv then return self:throw("Mode " .. mode .. " does not exist!", 0) end
return conv(rgb[1], rgb[2], rgb[3], rgb[4])
end

--- Converts the RGBA color (<r>,<g>,<b>,<a>) to a number in digital screen format. <mode> Specifies a mode, either 0, 2, 3 or 5 corresponding to Digital Screen color modes.
[nodiscard]
e2function number rgba2digi(r, g, b, a, mode)
local conv = converters[mode]
if not conv then return self:throw("Mode " .. mode .. " does not exist!", 0) end
return conv(r, g, b, a)
end