如何在只有 canvas 的情况下摆脱 emscripten 徽标和控制台?

How to get rid of emscripten logo and console while only having a canvas?

每当我用 emcc main.c -o index.html 编译我的 C 代码时,emscripten 都会生成一个 html 文件,其中包含他们的徽标、一些按钮和控制台。但我不想要那些。我只想要 canvas 可以显示我的 SDL 渲染内容的地方。

我做了一些研究,发现 。显然你必须输入 emcc --shell-file 并给它一些模板 html 作为参数。

所以我制作了一个模板 html 文件,就像这样

<html>
   <head>
      <title>Some title</title>
   </head>
   <body>
   </body>
</html>

但是当我运行emcc main.c -o index.html --shell-file template.html时却报错了。显然 emscripten 寻找一些像 - {{{ SCRIPT }}}.

这样的想法

所以我在体内添加了{{{ SCRIPT }}}。它编译得很好。但是,当我在 localhost:3000 中 运行 我的 index.html 时,我在控制台中收到一条错误消息,显示 cannot find addEventListener of undefined.

[N.B。我是 运行 一个 SDL 程序。 The one mentioned in their docs

我该怎么办?提前致谢

Here 是一个可以用作 index.html 的最小示例,假设您的 canvas 代码位于 index.js:

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<body>

    <!-- Create the canvas that the C++ code will draw into -->
    <canvas id="canvas" oncontextmenu="event.preventDefault()"></canvas>

    <!-- Allow the C++ to access the canvas element --> 
    <script type='text/javascript'>
        var Module = {
            canvas: (function() { return document.getElementById('canvas'); })()
        };
    </script>
    
    <!-- Add the javascript glue code (index.js) as generated by Emscripten -->
    <script src="index.js"></script>
    
</body>

</html>