Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support browser #2556

Open
6 tasks
eruvanos opened this issue Feb 9, 2025 · 3 comments
Open
6 tasks

Support browser #2556

eruvanos opened this issue Feb 9, 2025 · 3 comments

Comments

@eruvanos
Copy link
Member

eruvanos commented Feb 9, 2025

Feature requested

Support to distribute and play arcade based games within the browser.

Why?

Packaging Python does get easier and with utilisation of free GitHub Actions like New Arcade Game Template it is possible to automatically package Arcade based games as shippable artefacts for Win, MacOS and Linux.

These artefacts still have a huge drawback. They are reported as dangerous by the different OS, which can only be solved by paying a lot of money to sign the created artefacts and make them "trusted". Users have to actively ignore or disable security measures to play those games.

This is the reason why multiple GameJams already restrict submissions to browser supported artefacts.
In game development this is not a huge limitation, because other projects already support this (Unity, Godot).

In addition PyGame already have their foot in the door of browser support.

Why does it matter?

For me as Arcade Dev, I have a high interest, that my efforts I spend on Arcade, bring value to other game developer or people who learn Python. Projects like PyScript are IMHO the next big step to push Python to become the most used language. Supporting game development on a PyScript base would give us a push in attention and new users. It also would make it really simple to get started.

My current state of knowledge so far

  • There is already a old issue on Pyglet, to support browser: Run pyglet in a web browser pyglet/pyglet#949
    • pmp-p already had a working example of Pyglet using WebGL based on headless-mode and EGL rendering.
    • The PoC already covered changes to run the pyglet event loop async
    • The main difference between the PoC and a PyScript based setup is the runtime uses Python-WASM which provides an embed helper module, which should be easy to replace because it just provides the EGL context
    • Still pmp-p mentioned in a discord chat at PyScript

      most of the work in pyglet is freetype, input ( all of them ! ) and audio
      if i was about to make it real , i would use arcade -> pysdl2 + zengl , that way long term it would also work with micropython

    • Micropython support would be cool, because it has a smaller footprint, but libraries like pillow are already usable via pyodide, not sure if we would be able to find a way around that
  • @pushfoo already summarised some discussions on this topic in an old issue of arcade Enhancement request - Python Arcade for browser games #1215
  • Examples exist how to access WebGL 2 context of a html canvas: Using WebGL2 fails within pyodide (SDL_GL_CreateContext => EGL_BAD_CONFIG) emscripten-core/emscripten#21849
  • Pyglet devs already signalised, that they are open to support the work on browser support, but it is not their highest priority right now.

To compile all of these

  • Rendering should be possible and we have PoC that show that.
  • Things which are not covered
    • Inputs
    • Controller
    • Fonts
    • Audio

How I test:

Getting started with pyglet in the browser is pretty easy, it just not works :D

Store this as index.html and use python -m -m http.server -d ./ -b 127.0.0.1

<!doctype html>
<html>
<head>
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <link rel="stylesheet" href="https://pyscript.net/releases/2025.2.2/core.css">
    <script type="module" src="https://pyscript.net/releases/2025.2.2/core.js"></script>
</head>
<body>

<canvas id="canvas"></canvas>

<script type="py" config='{"packages":["pyglet"]}'>

    import pyglet
    print(pyglet.version)

    window = pyglet.window.Window()
    image = pyglet.resource.image("kitten.jpg")

    @window.event
    def on_draw():
        window.clear()

    image.blit(0, 0)

    pyglet.app.run()

</script>
</body>
</html>

I set up a repo to test it myself and use the fork of pmp-p: https://github.com/eruvanos/arcade-web-support/blob/pygbag/README-WEB.md

@eruvanos
Copy link
Member Author

eruvanos commented Feb 9, 2025

I took a look into some other setups, it looks like input handling should be easy to just redirect the html events like webwindow does it for ZenGL: https://github.com/szabolcsdombi/webwindow/blob/main/webwindow.py

@pushfoo
Copy link
Member

pushfoo commented Feb 10, 2025

If Clepto or someone else finds a WebGPU adapter layer, we can can expand on that template's element creation. Looks like webgpu is one of the accepted values? https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext

@Cleptomania
Copy link
Member

I don’t know that WebGPU is necessary. The only thing Arcade needs that isn’t supported by WebGL 2(and thus also provided by Emscripten as standard OpenGL) is geometry shaders, and WebGPU doesn’t support those either, so we’d still have to rework those pieces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants