This commit introduces a new header file `nanovg_gl46.h` that implements the NanoVG rendering context using OpenGL 4.6. The new backend utilizes Direct State Access (DSA) functions, immutable texture storage, and explicit layout qualifiers. It includes definitions for creating and deleting the rendering context, as well as functions for handling images with OpenGL 4.6.
78 lines
1.9 KiB
Lua
78 lines
1.9 KiB
Lua
effect = nil
|
|
video = nil
|
|
ctx = nil
|
|
|
|
timeDisplayText = ""
|
|
dateDisplayText = ""
|
|
|
|
timer = 0.0
|
|
|
|
function _create()
|
|
video = Texture.FromGStreamer("filesrc location=" .. Resolve("video.mkv"))
|
|
|
|
local fxSrc = [[uniform sampler2D uTexture;
|
|
|
|
void main() {
|
|
vec2 uv = vUV;
|
|
|
|
for (int i = 0; i < uNumDisplays; i++) {
|
|
vec4 displayNorm = uDisplayNorm[i];
|
|
|
|
if (vUV.x >= displayNorm.x && vUV.x <= displayNorm.x + displayNorm.z &&
|
|
vUV.y >= displayNorm.y && vUV.y <= displayNorm.y + displayNorm.w) {
|
|
FragColor = texture(uTexture, GetDisplayUV(uTexture, i));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
]]
|
|
effect = Effect.new(fxSrc)
|
|
|
|
ctx = GraphicsContext.new()
|
|
|
|
local fontPath = Resolve("font.otf")
|
|
ctx:CreateFont("font", fontPath)
|
|
|
|
UpdateTimeAndDate()
|
|
end
|
|
|
|
function UpdateTimeAndDate()
|
|
local now = os.date("*t")
|
|
timeDisplayText = string.format("%02d:%02d", now.hour, now.min)
|
|
dateDisplayText = os.date("%A, %B %d, %Y")
|
|
end
|
|
|
|
function _update(dt)
|
|
timer = timer + dt
|
|
|
|
if timer >= 0.5 then
|
|
timer = 0.0
|
|
UpdateTimeAndDate()
|
|
end
|
|
end
|
|
|
|
function _render()
|
|
gl.Clear(0, 0, 0, 1.0)
|
|
effect:Use()
|
|
effect:SetTexture("uTexture", video, 0)
|
|
effect:Render()
|
|
|
|
ctx:BeginFrame(DesktopSize.x, DesktopSize.y, DesktopSize.x / DesktopSize.y)
|
|
|
|
local xPos = 80.0
|
|
local yPos = 120.0
|
|
local timeFontSize = 80
|
|
local dateFontSize = 28
|
|
|
|
ctx:FontSize(timeFontSize)
|
|
ctx:FontFace("font")
|
|
ctx:FillColor(RGBAf(1, 1, 1, 0.75))
|
|
ctx:TextAlign(Align.RIGHT | Align.BOTTOM)
|
|
ctx:Text(Displays[1].x + Displays[1].z - xPos, Displays[1].y + Displays[1].w - yPos, timeDisplayText)
|
|
|
|
ctx:FontSize(dateFontSize)
|
|
ctx:FillColor(RGBAf(1, 1, 1, 0.45))
|
|
ctx:Text(Displays[1].x + Displays[1].z - xPos, Displays[1].y + Displays[1].w - (yPos + timeFontSize + 8), dateDisplayText)
|
|
|
|
ctx:EndFrame()
|
|
end |