# Web target - progress and plans

**URL:** https://forum.castle-engine.io/t/web-target-progress-and-plans/789
**Category:** News
**Created:** [April 8, 2023, 9:20am UTC](https://forum.castle-engine.io/t/web-target-progress-and-plans/789 "2023-04-08T09:20:03Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [April 8, 2023, 9:20am UTC](https://forum.castle-engine.io/t/web-target-progress-and-plans/789/1 "2023-04-08T09:20:04Z")

</div>

| [![WebGL](https://forum.castle-engine.io/uploads/default/original/2X/2/212a6cf1f64d440181db34a7cb74345c8e5624e0.png)](https://castle-engine.io/wp/wp-content/uploads/2023/04/bitmapa.png "WebGL") |

After the big engine release of 7.0 (coming really soon!), I’m dedicated to focus on adding the [web target](https://castle-engine.io/roadmap#web) as a new engine platform.

The goal is simple: allow you to recompile more-or-less any application you wrote using _Castle Game Engine_ (using `TCastleWindow`) to the web. So you can put your application on a website, as part of a normal HTML webpage, and users can play it instantly, without the need to download / install any native application or plugin.

**How:**

- We’re using FPC [WebAssembly](https://wiki.freepascal.org/WebAssembly) target. Huge thank you go to the whole FPC team of course for making it possible!

Possibly there will be some additional “glue” bits done using [pas2js](https://wiki.freepascal.org/pas2js) (such “glue” is necessary as WebAssembly doesn’t otherwise get access to JavaScript APIs available in a web browser).

- We will render using [WebGL 1.0](https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API), with optional WebGL 2.0 features. This is very similar to current rendering on mobile, where we use [OpenGL ES 2.0, with optional OpenGL ES 3.0 features](https://castle-engine.io/wp/2023/03/12/mobile-opengles-rendering-upgrades-occlusion-query-anisotropic-filtering-3d-textures-shadows-plus-new-occlusion-query-demo/).

- For audio, we will add a new sound backend using [WebAudio](https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API). This will be the default sound backend on the web (like the [OpenAL](https://castle-engine.io/openal) is now the default backend on non-web platforms).

- For data delivery, we know we’ll have to invent a simple format to carry our game data as one big binary blob. The simple plan is to just pack game data into zip.

- For development purposes, likely we’ll add a _“Run simple webserver on localhost”_ feature, to allow you easily run WebAssembly applications. This can be done using a number of things, I like most the idea of using [fpWeb](https://wiki.lazarus.freepascal.org/fcl-web) which can instantiate a [standalone HTTP server](https://wiki.lazarus.freepascal.org/fphttpserver) in just a few lines of code.

**What we have now:**

- Branch [webassm\_platformer\_test](https://github.com/castle-engine/castle-engine/tree/webassm_platformer_test) in CGE contains a code that compiles (but it is not functional yet!) for WebAssembly. This means that CGE compiles, and also build tool supports a new OS/CPU. So you can enter any CGE project, and execute on command-line:

```
castle-engine compile --os=wasi --cpu=wasm32
# or
castle-engine compile --os=wasi --cpu=wasm32 --mode=debug
```
- We’ve encountered [FPC issue #40229 (Wasm32 symbol xxx without index value error)](https://gitlab.com/freepascal.org/fpc/source/-/issues/40229) but it is now happily fixed 🙂 Many thanks go to _Nikolay Nikolov_ from FPC team for fixing, and _Andrzej Kilijański_ for preparing a code to easily reproduce the issue.

- _Trung Le (Kagamma)_ has been doing lots of work with CGE + FPC WebAssembly. His fork contains a branch [wasm32-wasi-port](https://github.com/Kagamma/castle-engine/tree/wasm32-wasi-port) with lots of active work. I absolutely expect that we’ll merge it to CGE [webassm\_platformer\_test](https://github.com/castle-engine/castle-engine/tree/webassm_platformer_test) at some point, and then to master branch 🙂

- As noted by _Trung Le (Kagamma)_, the important issue hanging on FPC now is [#39547 (wasm32-wasi: Cannot create dynamic library)](https://gitlab.com/freepascal.org/fpc/source/-/issues/39547). Go ahead and upvote it 🙂

- File-size tests are promising. Compilation of [examples/platformer](https://github.com/castle-engine/castle-engine/tree/webassm_platformer_test/examples/platformer), which practically uses 100% of CGE units, yields a binary `platformer.wasm` that has 16 MB. Gzipped it has 3.4 MB. 

I want to thank everyone involved in this and let’s push forward! Web target is a really cool feature, from my talks I know it’s an important feature for many CGE users, and I feel we have it in our reach. Let’s keep coding and enjoy making games 🙂

---

<div class="post-metadata">

### Author: ![sledge](https://forum.castle-engine.io/letter_avatar_proxy/v4/letter/s/a587f6/32.png) [@sledge](https://forum.castle-engine.io/u/sledge)
#### Post date: [April 14, 2023, 1:56pm UTC](https://forum.castle-engine.io/t/web-target-progress-and-plans/789/2 "2023-04-14T13:56:21Z")

</div>

This are really great news ! Wow !

I think Web is super cool, because everybody is able to start your Game / App without to have it to install, or to download. In addition to this, it is platform independent ! Just great. Thanks for implementing this.

I am not a big fan of the \*.wasm, because of its file size! But you said: gzip / Brotli can compress it. So the browser read it on the fly. But the browser / frontend needs time to decompress it? Any numbers about decompr. time ? And does every browser support gzip (mobile, linux, playstation, etc)?

Can you give an example, how to put a \*.gzip into a adress, or html. Usually i always point to an html file. Like: [https://test/my\_test.html](https://test/my_test.html)

EDIT:  
Can i use any compression-app like 7zip, to zip it into a \*.gzip ?

---

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [April 15, 2023, 3:39am UTC](https://forum.castle-engine.io/t/web-target-progress-and-plans/789/3 "2023-04-15T03:39:35Z")

</div>

For the compression, really every browser in existence supports at least gzip. And 96% of them support Brotli. See

> **["gzip" | Can I use... Support tables for HTML5, CSS3, etc](https://caniuse.com/?search=gzip)**
>
> "Can I use" provides up-to-date browser support tables for support of front-end web technologies on desktop and mobile web browsers.

> **[Content-Encoding - HTTP | MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding#compressing_with_gzip)**
>
> The Content-Encoding representation header lists any encodings that have been applied to the representation (message payload), and in what order.
> This lets the recipient know how to decode the representation in order to obtain the original payload...

> **[Brotli Accept-Encoding/Content-Encoding | Can I use... Support tables for...](https://caniuse.com/brotli)**
>
> "Can I use" provides up-to-date browser support tables for support of front-end web technologies on desktop and mobile web browsers.

The time to decompress is really negligible – I haven’t ever observed it being relevant at all. The decompression happens during downloading, and in practice decompression is likely faster than download, so you don’t really observe any delay. Pretty much everything you see on the Internet in your browser, including this very WWW page of our forum, is compressed – looking at WWW headers in Firefox console, I see my Firefox talks to our forum with Brotli.

As for how to make the file compressed on the server: basically you can do nothing. Your www server can compress it on the fly. If you think it’s an overkill, remember this is already being done to most of data 🙂 See docs of Apache, Nginx how to configure what to compress. Alternatively you can tell the WWW browser it is already compressed, and then you can compress it yourself.

---

<div class="post-metadata">

### Author: ![sledge](https://forum.castle-engine.io/letter_avatar_proxy/v4/letter/s/a587f6/32.png) [@sledge](https://forum.castle-engine.io/u/sledge)
#### Post date: [April 23, 2023, 6:05pm UTC](https://forum.castle-engine.io/t/web-target-progress-and-plans/789/4 "2023-04-23T18:05:25Z")

</div>

Thanks for all the informations !

> I see my Firefox talks to our forum with Brotli.

Cool…need to check this out.

> As for how to make the file compressed on the server: basically you can do nothing.

You mean especially for the \*.wasm file, i guess. Or even: png, js, css, etc ? Anyways, i need to investigate about gzip / brotli compressions.

---

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [April 24, 2023, 3:30pm UTC](https://forum.castle-engine.io/t/web-target-progress-and-plans/789/5 "2023-04-24T15:30:57Z")

</div>

> [@sledge](#):
>
> > As for how to make the file compressed on the server: basically you can do nothing.
> 
> You mean especially for the \*.wasm file, i guess. Or even: png, js, css, etc ? Anyways, i need to investigate about gzip / brotli compressions.

Everything.

There are rules on each WWW server (Apache, Nginx…) to configure what to compress, so that e.g. PNG are no longer compressed on-the-fly with GZIP (which would generally make little gain as PNGs already employ a more specialized version of GZIP compression). But basically most things are compressed. Pretty much all HTML, CSS etc. you see now on any website is compressed 🙂 You can look at Firefox / Google Chrome Developer tools, see at headers sent – pretty much all browsers say “we accept gzip and brotli”, pretty much all www servers answer “cool, so this is your content in gzip / brotli”.

In case of CGE, this would mean we:

- compress \*.wasm with gzip / brotli (and let browser decompress on-the-fly)
- optionally compress even CGE data (which will already be .zip) using gzip / brotli. We’ll measure whether it makes sense, but we can do it.

---

<div class="post-metadata">

### Author: ![sledge](https://forum.castle-engine.io/letter_avatar_proxy/v4/letter/s/a587f6/32.png) [@sledge](https://forum.castle-engine.io/u/sledge)
#### Post date: [April 24, 2023, 7:17pm UTC](https://forum.castle-engine.io/t/web-target-progress-and-plans/789/6 "2023-04-24T19:17:32Z")

</div>

> In case of CGE, this would mean we:
> 
> • compress \*.wasm with gzip / brotli (and let browser decompress on-the-fly)  
> • optionally compress even CGE data (which will already be .zip) using gzip / brotli. We’ll measure whether it makes sense, but we can do it.

Okay. This sounds good.

I think **i have too less knowledge** about the backend processes at server-side. I just know, that if i compress files by my own via 7zip f.e. they are much smaller than just uploading them “raw” onto my server. Also compressed files by my own, the upload / download is faster than just “raw” files.

---

<div class="post-metadata">

### Author: ![coco](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/coco/32/2043_2.png) [@coco](https://forum.castle-engine.io/u/coco)
#### Post date: [August 14, 2024, 9:39am UTC](https://forum.castle-engine.io/t/web-target-progress-and-plans/789/7 "2024-08-14T09:39:58Z")

</div>

more than one year has passed, any updates on this?

---

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [August 15, 2024, 1:17pm UTC](https://forum.castle-engine.io/t/web-target-progress-and-plans/789/8 "2024-08-15T13:17:28Z")

</div>

@coco Not yet.

The WebGL target is still planned, and I consider it the most important thing to do after 7.0 release (I talk about it in the roadmap [Roadmap | Manual | Castle Game Engine](https://castle-engine.io/roadmap) , I mention this in my upcoming talk at Dev Days of Summer 2024, [Conferences! Register for my upcoming talk at Dev Days of Summer (August 2024), catch me in Cologne (October 2024), watch my past talk from ITDevCon 2023 – Castle Game Engine](https://castle-engine.io/wp/2024/08/10/conferences-register-for-my-upcoming-talk-at-dev-days-of-summer-august-2024-catch-me-in-cologne-october-2024-watch-my-past-talk-from-itdevcon-2023/) ). I’m also in contact with _Michael Van Canneyt_, who oversaw the FPC+WebAssembly and who promised to help in any way he can (from the FPC side) to make CGE on the web.

At one point in the past we even got everything (the engine + platformer example) to compile, it’s on a branch [GitHub - castle-engine/castle-engine at webassm\_platformer\_test](https://github.com/castle-engine/castle-engine/tree/webassm_platformer_test) . Alas, there’s some work ahead from “it compiles” to “it actually works” 🙂 Right now it just waits for my time to do it.

If you’d like to help, then supporting Castle Game Engine, financially or with your knowledge ( [https://www.patreon.com/castleengine](https://www.patreon.com/castleengine) , [Helping in the engine development | Manual | Castle Game Engine](https://castle-engine.io/helping.php) , [Donate to Castle Game Engine | Manual | Castle Game Engine](https://castle-engine.io/donate_other.php) ) is very much appreciated. For a few months now, 100% of my life time is spent on _Castle Game Engine_, I count on your support to release 7.0 and then make WebGL port and everything else from [Roadmap | Manual | Castle Game Engine](https://castle-engine.io/roadmap) 🙂
