mrk-its / bevy_webgl2

WebGL2 renderer plugin for Bevy game engine
MIT License
172 stars 46 forks source link

Control canvas window size by rust code ? #10

Closed starccy closed 3 years ago

starccy commented 3 years ago

WindowDescriptor is useless on the canvas window. If use js to control the size, it is also difficult to let rust know the concrete window's size.
Would it be better to add a new resource like CanvasWindowDescriptor or something to store user-defined size? Then we can set the inner size of the canvas before its initialized.

mockersf commented 3 years ago

the canvas size is actually controlled by the resolution you set for winit (see here) which is controlled by the WindowDescriptor from bevy It can also be resized (you would call set_resolution which will forward the new resolution all the way to this function that will change the canvas size)

starccy commented 3 years ago

So I used a wrong way to resize window on wasm target. Thanks for your advise and I'd like have a try.

mrk-its commented 3 years ago

@starccy @mockersf moreover bevy_webgl2 handles window resize events and updates gl viewport properly - you can test it by by changing zoom level in the browser - you should see the same behavior like in native apps (for example sprite size will stay the same and 3d scenes will scale) BTW web apps behaves currently much better during window (canvas) scaling than native, because there is no flickering :)

ostwilkens commented 3 years ago

Shameless plug(in): bevy_web_fullscreen Might not be exactly what you're after, but it can be repurposed.

starccy commented 3 years ago

Sorry for a long time no reply. After learning bevy a lot, I have known my question is so easy to solve. Also thanks for the bevy_web_fullscreen project from @ostwilkens, it very helpful for me. I think this issue can be closed.