diff --git a/src/main.ts b/src/main.ts index fcf1b3f..e5c652d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,6 +3,7 @@ import { ImGuiIO } from "imgui-js" import { ImVec4 } from "imgui-js"; import { ImVec2 } from "imgui-js"; +import * as PIXI from "pixi.js"; async function main(): Promise { @@ -26,26 +27,52 @@ // Setup style ImGui.StyleColorsLight(); - const output: HTMLElement = document.getElementById("output") || document.body; - const canvas: HTMLCanvasElement = document.createElement("canvas"); - output.appendChild(canvas); - canvas.tabIndex = 1; - canvas.style.position = "absolute"; - canvas.style.left = "0px"; - canvas.style.right = "0px"; - canvas.style.top = "0px"; - canvas.style.bottom = "0px"; - canvas.style.width = "100%"; - canvas.style.height = "100%"; - ImGui_Impl.Init(canvas); + let settings = { width: 1, height: 1, antialias: true }; - window.requestAnimationFrame(loop); + let app : PIXI.Application = new PIXI.Application(settings); + + const output: HTMLElement = document.getElementById("output") || document.body; + output.appendChild(app.view); + app.view.tabIndex = 1; + app.view.style.position = "absolute"; + app.view.style.left = "0px"; + app.view.style.right = "0px"; + app.view.style.top = "0px"; + app.view.style.bottom = "0px"; + app.view.style.width = "100%"; + app.view.style.height = "100%"; + ImGui_Impl.Init(app.view); + + app.ticker.add( + (deltaTime: number) => + { + const dt: number = deltaTime * 1 / (1000 * PIXI.settings.TARGET_FPMS); + + ImGui_Impl.NewFrame(dt); + ImGui.NewFrame(); + + update(dt); + + ImGui.EndFrame(); + ImGui.Render(); + + app.render(); + } + ); + + let resizeFunc = function() + { + app.renderer.resize(window.innerWidth, window.innerHeight); + }; + + window.onresize = resizeFunc; + resizeFunc(); } const clearColor:ImVec4 = new ImVec4(0.7, 0.9, 1, 1); let windowOpen: boolean = true; let text: string = "text"; -function render(timeElapsed: number): void +function update(timeElapsed: number): void { ImGui.SetNextWindowSize(new ImVec2(600, 400), ImGui.ImGuiCond.Always); ImGui.Begin("Test Window", (_ = windowOpen) => windowOpen = _, 0);