Newer
Older
7gui / src / main.js
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import * as ImGui_Impl from "../imgui-js/example/imgui_impl";
import * as ImGui from "imgui-js";
import { ImVec4 } from "imgui-js";
function main() {
    return __awaiter(this, void 0, void 0, function* () {
        console.log("main()");
        yield ImGui.default();
        window.requestAnimationFrame(init);
    });
}
function init() {
    console.log("init()");
    console.log("Total allocated space (uordblks) @ _init:", ImGui.bind.mallinfo().uordblks);
    // Setup Dear ImGui binding
    ImGui.IMGUI_CHECKVERSION();
    ImGui.CreateContext();
    const io = ImGui.GetIO();
    io.ConfigFlags |= ImGui.ConfigFlags.NavEnableKeyboard; // Enable Keyboard Controls
    // Setup style
    ImGui.StyleColorsDark();
    const output = document.getElementById("output") || document.body;
    const canvas = 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);
    window.requestAnimationFrame(loop);
}
const clearColor = new ImVec4(0, 0, 0, 1);
function loop(time) {
    ImGui_Impl.NewFrame(time);
    ImGui.NewFrame();
    ImGui.EndFrame();
    // Rendering
    ImGui.Render();
    const gl = ImGui_Impl.gl;
    if (gl) {
        gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
        gl.clearColor(clearColor.x, clearColor.y, clearColor.z, clearColor.w);
        gl.clear(gl.COLOR_BUFFER_BIT);
        //gl.useProgram(0); // You may want this if using this code in an OpenGL 3+ context where shaders may be bound
    }
    const ctx = ImGui_Impl.ctx;
    if (ctx) {
        // ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
        ctx.fillStyle = `rgba(${clearColor.x * 0xff}, ${clearColor.y * 0xff}, ${clearColor.z * 0xff}, ${clearColor.w})`;
        ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
    }
    ImGui_Impl.RenderDrawData(ImGui.GetDrawData());
    window.requestAnimationFrame(loop);
}
(function () {
    window.onload = main;
})();
//# sourceMappingURL=main.js.map