{"id":2985,"date":"2025-01-01T18:49:23","date_gmt":"2025-01-01T18:49:23","guid":{"rendered":"https:\/\/timallanwheeler.com\/blog\/?p=2985"},"modified":"2025-01-01T18:51:46","modified_gmt":"2025-01-01T18:51:46","slug":"emscripten-is-neat","status":"publish","type":"post","link":"https:\/\/timallanwheeler.com\/blog\/2025\/01\/01\/emscripten-is-neat\/","title":{"rendered":"Emscripten is Neat"},"content":{"rendered":"\n<p>I spent most of December on vacation, so no big post. However, I did learn about <a href=\"https:\/\/emscripten.org\/index.html\">Emscripten<\/a>, a C++ compiler that produces an executable in <a href=\"https:\/\/webassembly.org\/\">WebAssembly<\/a>. I tried it out and have to say, it was remarkably easy to get something up and running. <\/p>\n\n\n\n<p>I made a very simple crossword game. You you can try it out <a href=\"https:\/\/timallanwheeler.com\/data\/posts\/2025_01_emscripten\/crossword.html\">here<\/a>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/timallanwheeler.com\/data\/posts\/2025_01_emscripten\/crossword.html\"><img loading=\"lazy\" decoding=\"async\" width=\"475\" height=\"477\" src=\"https:\/\/timallanwheeler.com\/blog\/wp-content\/uploads\/2025\/01\/2025-01-01_10-39.png\" alt=\"\" class=\"wp-image-2987\" srcset=\"https:\/\/timallanwheeler.com\/blog\/wp-content\/uploads\/2025\/01\/2025-01-01_10-39.png 475w, https:\/\/timallanwheeler.com\/blog\/wp-content\/uploads\/2025\/01\/2025-01-01_10-39-300x300.png 300w, https:\/\/timallanwheeler.com\/blog\/wp-content\/uploads\/2025\/01\/2025-01-01_10-39-150x150.png 150w\" sizes=\"auto, (max-width: 475px) 100vw, 475px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p class=\"has-text-align-center has-small-font-size\">Best on desktop. While it does load in the browser, it is looking for key events, which is really cumbersome on mobile.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>This was written with <a href=\"https:\/\/www.libsdl.org\/\">SDL2<\/a> and <a href=\"https:\/\/github.com\/ocornut\/imgui\">Dear ImGUI<\/a>.<\/p>\n\n\n\n<p>Compilation is pretty straightforwad. Instead of running <code>gcc &lt;srcs&gt; &lt;libs&gt;<\/code> you run <code>emcc &lt;srcs&gt; &lt;libs&gt;<\/code>. The compiler does some magic to reinterpret use of OpenGL with WebGL, and spits out a .wasm binary blob, a .js script that can execute it, and a .html page that runs it all. My game link above is simply to that .html page.<\/p>\n\n\n\n<p>To test it locally without uploading it to a web page, you can simply start a Python server in your dev directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">python -m http.server<\/code><\/pre>\n\n\n\n<p>and then open your .html file in the browser:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">http:\/\/localhost:8000\/your_thing.html<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>I spend a lot of time tinkering with games and other programs in C++, but I&#8217;m developing on a Linux machine. As a result, I can&#8217;t really share my games with my friends. Emscripten might be a nice way to achieve that.<\/p>\n\n\n\n<p>Happy 2025 everyone. Hope its a good one.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I spent most of December on vacation, so no big post. However, I did learn about Emscripten, a C++ compiler that produces an executable in WebAssembly. I tried it out and have to say, it was remarkably easy to get something up and running. I made a very simple crossword game. You you can try [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2985","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/timallanwheeler.com\/blog\/wp-json\/wp\/v2\/posts\/2985","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/timallanwheeler.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/timallanwheeler.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/timallanwheeler.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/timallanwheeler.com\/blog\/wp-json\/wp\/v2\/comments?post=2985"}],"version-history":[{"count":8,"href":"https:\/\/timallanwheeler.com\/blog\/wp-json\/wp\/v2\/posts\/2985\/revisions"}],"predecessor-version":[{"id":2996,"href":"https:\/\/timallanwheeler.com\/blog\/wp-json\/wp\/v2\/posts\/2985\/revisions\/2996"}],"wp:attachment":[{"href":"https:\/\/timallanwheeler.com\/blog\/wp-json\/wp\/v2\/media?parent=2985"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/timallanwheeler.com\/blog\/wp-json\/wp\/v2\/categories?post=2985"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/timallanwheeler.com\/blog\/wp-json\/wp\/v2\/tags?post=2985"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}