diff --git a/src/imgui_impl.ts b/src/imgui_impl.ts index 0a80b55..e5a770e 100644 --- a/src/imgui_impl.ts +++ b/src/imgui_impl.ts @@ -645,6 +645,8 @@ canvas.addEventListener("contextmenu", canvas_on_contextmenu); canvas.addEventListener("wheel", canvas_on_wheel); } + + CreateDeviceObjects(); } export function Shutdown(): void { @@ -674,7 +676,7 @@ } } -export function CreateFontsTexture(): void { +function CreateFontsTexture(): void { const io = ImGui.GetIO(); // Backup GL state @@ -703,13 +705,13 @@ gl && last_texture && gl.bindTexture(gl.TEXTURE_2D, last_texture); } -export function DestroyFontsTexture(): void { +function DestroyFontsTexture(): void { const io = ImGui.GetIO(); io.Fonts.TexID = null; gl && gl.deleteTexture(g_FontTexture); g_FontTexture = null; } -export function CreateDeviceObjects(): void { +function CreateDeviceObjects(): void { const vertex_shader: string[] = [ "#version 300 es", "uniform mat4 ProjMtx;", @@ -758,10 +760,9 @@ g_VboHandle = gl && gl.createBuffer(); g_ElementsHandle = gl && gl.createBuffer(); - CreateFontsTexture(); } -export function DestroyDeviceObjects(): void { +function DestroyDeviceObjects(): void { DestroyFontsTexture(); gl && gl.deleteVertexArray(g_VaoHandle); g_VaoHandle = null; diff --git a/src/imgui_impl.ts b/src/imgui_impl.ts index 0a80b55..e5a770e 100644 --- a/src/imgui_impl.ts +++ b/src/imgui_impl.ts @@ -645,6 +645,8 @@ canvas.addEventListener("contextmenu", canvas_on_contextmenu); canvas.addEventListener("wheel", canvas_on_wheel); } + + CreateDeviceObjects(); } export function Shutdown(): void { @@ -674,7 +676,7 @@ } } -export function CreateFontsTexture(): void { +function CreateFontsTexture(): void { const io = ImGui.GetIO(); // Backup GL state @@ -703,13 +705,13 @@ gl && last_texture && gl.bindTexture(gl.TEXTURE_2D, last_texture); } -export function DestroyFontsTexture(): void { +function DestroyFontsTexture(): void { const io = ImGui.GetIO(); io.Fonts.TexID = null; gl && gl.deleteTexture(g_FontTexture); g_FontTexture = null; } -export function CreateDeviceObjects(): void { +function CreateDeviceObjects(): void { const vertex_shader: string[] = [ "#version 300 es", "uniform mat4 ProjMtx;", @@ -758,10 +760,9 @@ g_VboHandle = gl && gl.createBuffer(); g_ElementsHandle = gl && gl.createBuffer(); - CreateFontsTexture(); } -export function DestroyDeviceObjects(): void { +function DestroyDeviceObjects(): void { DestroyFontsTexture(); gl && gl.deleteVertexArray(g_VaoHandle); g_VaoHandle = null; diff --git a/src/main.ts b/src/main.ts index e33b7ef..61306c1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -39,10 +39,6 @@ ImGui_Impl.Init(app); - ImGui.StyleColorsLight(); - - ImGui_Impl.CreateDeviceObjects(); - app.ticker.add( (deltaTime: number) => { @@ -60,13 +56,22 @@ let bg: PIXI.Graphics = new PIXI.Graphics(); bg.beginFill(0xFF0000); - bg.drawRect(0, 0, 600, 600); + bg.drawRect(100, 100, 300, 300); bg.endFill(); + let styleCb: () => void = () => { ImGui.StyleColorsLight(); }; + const imgui: ImGuiWindow = new ImGuiWindow(512, 512, update); + const imgui2: ImGuiWindow = new ImGuiWindow(512, 512, update); + imgui2.x = 200; + imgui2.y = 400; + + imgui.withContext(styleCb); + imgui2.withContext(styleCb); - app.stage.addChild(bg); app.stage.addChild(imgui); + app.stage.addChild(bg); + app.stage.addChild(imgui2); window.onresize = resizeFunc; resizeFunc(); @@ -76,8 +81,8 @@ let text: string = "text"; function update(timeElapsed: number): void { - ImGui.SetNextWindowPos(new ImVec2(0, 0)); - ImGui.SetNextWindowSize(new ImVec2(600, 400), ImGui.ImGuiCond.Always); + //ImGui.SetNextWindowPos(new ImVec2(0, 0)); + ImGui.SetNextWindowSize(new ImVec2(500, 500), ImGui.ImGuiCond.Always); ImGui.Begin("Test Window"); if (ImGui.Button("Add Text")) {