From f5dd7d7831e0b354c2e5e15579b92efeacd09545 Mon Sep 17 00:00:00 2001 From: Darren Eberly Date: Sat, 27 Dec 2025 02:52:19 -0500 Subject: [PATCH 1/2] Remove pixel scaling for default framebuffer from WebGL backend --- arcade/gl/backends/webgl/framebuffer.py | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/arcade/gl/backends/webgl/framebuffer.py b/arcade/gl/backends/webgl/framebuffer.py index a5bf4a18cf..a4d30975b3 100644 --- a/arcade/gl/backends/webgl/framebuffer.py +++ b/arcade/gl/backends/webgl/framebuffer.py @@ -256,7 +256,7 @@ def __init__(self, ctx: WebGLContext): @DefaultFrameBuffer.viewport.setter def viewport(self, value: tuple[int, int, int, int]): - # This is the exact same as the WebGLFramebuffer setter + # This is very similar to the OpenGL backend setter # WebGL backend doesn't need to handle pixel scaling for the # default framebuffer like desktop does, the browser does that # for us. However we need a separate implementation for the @@ -264,13 +264,7 @@ def viewport(self, value: tuple[int, int, int, int]): if not isinstance(value, tuple) or len(value) != 4: raise ValueError("viewport shouldbe a 4-component tuple") - ratio = self.ctx.window.get_pixel_ratio() - self._viewport = ( - int(value[0] * ratio), - int(value[1] * ratio), - int(value[2] * ratio), - int(value[3] * ratio), - ) + self._viewport = value if self._ctx.active_framebuffer == self: self._ctx._gl.viewport(*self._viewport) @@ -281,23 +275,11 @@ def viewport(self, value: tuple[int, int, int, int]): @DefaultFrameBuffer.scissor.setter def scissor(self, value): - # This is the exact same as the WebGLFramebuffer setter - # WebGL backend doesn't need to handle pixel scaling for the - # default framebuffer like desktop does, the browser does that - # for us. However we need a separate implementation for the - # function because of ABC if value is None: self._scissor = None if self._ctx.active_framebuffer == self: self._ctx._gl.scissor(*self._viewport) else: - ratio = self.ctx.window.get_pixel_ratio() - self._scissor = ( - int(value[0] * ratio), - int(value[1] * ratio), - int(value[2] * ratio), - int(value[3] * ratio), - ) - + self._scissor = value if self._ctx.active_framebuffer == self: self._ctx._gl.scissor(*self._scissor) From 7fa32e92b080f385526802e95bd8253e823d1304 Mon Sep 17 00:00:00 2001 From: Maic Siemering Date: Sat, 27 Dec 2025 15:57:55 +0100 Subject: [PATCH 2/2] Add local scripts support for testing in the web environment, update web readme --- webplayground/README.md | 26 +++++-- webplayground/index.tpl | 23 ++++++ webplayground/local.tpl | 75 +++++++++++++++++++ webplayground/local_run.tpl | 80 +++++++++++++++++++++ webplayground/local_scripts/README.md | 59 +++++++++++++++ webplayground/local_scripts/example_test.py | 43 +++++++++++ webplayground/server.py | 42 ++++++++++- 7 files changed, 340 insertions(+), 8 deletions(-) create mode 100644 webplayground/local.tpl create mode 100644 webplayground/local_run.tpl create mode 100644 webplayground/local_scripts/README.md create mode 100644 webplayground/local_scripts/example_test.py diff --git a/webplayground/README.md b/webplayground/README.md index df6b4b0df5..1491686e64 100644 --- a/webplayground/README.md +++ b/webplayground/README.md @@ -5,18 +5,30 @@ An http server is provided with the `server.py` file. This file can be run with The index page will provide a list of all Arcade examples. This is generated dynamically on the fly when the page is loaded, and will show all examples in the `arcade.examples` package. This generates links which can be followed to open any example in the browser. -There are some pre-requesites to running this server. It assumes that you have the `development` branch of Pyglet -checked out and in a folder named `pyglet` directly next to your Arcade repo directory. You will also need to have -the `build` and `flit` packages from PyPi installed. These are used by Pyglet and Arcade to build wheel files, -but are not generally installed for local development. +## Testing Local Scripts -Assuming you have Pyglet ready to go, you can then start the server. It will build wheels for both Pyglet and Arcade, and copy them -into this directory. This means that if you make any, you will need to restart this server in order to build new wheels. +You can now test your own local scripts **without restarting the server**! + +1. Navigate to `http://localhost:8000/local` in your browser +2. Place your Python scripts in the `local_scripts/` directory +3. Scripts should have a `main()` function as the entry point +4. The page will automatically list all `.py` files in that directory +5. Click any script to run it in the browser +6. Edit your scripts and refresh the browser page to see changes - no server restart needed! + +See `local_scripts/README.md` and `local_scripts/example_test.py` for more details and examples. + +## Prerequisites + +You will need to have `uv` installed to build the Arcade wheel. You can install it with: + +When you start the server, it will automatically build an Arcade wheel and copy it into this directory. +This means that if you make any changes to Arcade code, you will need to restart the server to build a new wheel with your changes. ## How does this work? The web server itself is built with a nice little HTTP server library named [Bottle](https://github.com/bottlepy/bottle). We need to run an HTTP server locally -to load anything into WASM in the browser, it will not work if we just server it files directly due to browser security constraints. For the Arcade examples specifically, +to load anything into WASM in the browser, as it will not work if we just serve files directly due to browser security constraints. For the Arcade examples specifically, we are taking advantage of the fact that the example code is packaged directly inside of Arcade to enable executing them in the browser. If we need to add extra code that is not part of the Arcade package, that will require extension of this server to handle packaging it properly for loading into WASM, and then diff --git a/webplayground/index.tpl b/webplayground/index.tpl index 4c5a8e11b5..66e42fd740 100644 --- a/webplayground/index.tpl +++ b/webplayground/index.tpl @@ -3,9 +3,32 @@ Arcade Examples + +

Arcade Examples

+ 🧪 Test Local Scripts +

Built-in Examples: