lordmauve / wasabi2d

Cutting-edge 2D game framework for Python
https://wasabi2d.readthedocs.io/
GNU Lesser General Public License v3.0
154 stars 24 forks source link

How to render pygame Surface? #40

Open mkraljt opened 4 years ago

mkraljt commented 4 years ago

pygamezero examples use pygame Surface to render and test/set pixels, eg Tron example.

How do you render a pygame Surface in Wasabi2D? Or is there an alternative for Surface use-cases in pygamezero examples?

lordmauve commented 4 years ago

There isn't. In OpenGL there are framebuffer objects, but I think that exposing those for general use might be a long way off.

How I wrote Tron in Pygame Zero isn't exactly how I would write it with hardware accelerated graphics. I'd just keep creating line segments and trust that it will remain fast.

einarf commented 4 years ago

Could in theory open up for people to write to pygame surfaces and upload to texture: https://github.com/moderngl/moderngl-window/blob/master/examples/advanced/pygame2.py

That could be an awesome or a terrible a idea depending on how you see it.

mkraljt commented 4 years ago

Yes for the Tron game, it worked well with line segments.

And looks like you are adding tile-maps for 1.4, which was the other use I was anticipating for pygame surface

lordmauve commented 4 years ago

Yes, I think this is a good idea. This would allow people to migrate from Pygame and immediately get the benefit of things like post-processing effects.

lordmauve commented 4 years ago

Via @einarf

https://github.com/moderngl/moderngl-window/blob/master/examples/advanced/pygame2.py

Works with alpha just using pygame.Surface(self.pg_res, flags=pygame.SRCALPHA) I get 4 bytes width height in pg_screen.get_view('1')

lordmauve commented 4 years ago

And looks like you are adding tile-maps for 1.4, which was the other use I was anticipating for pygame surface

@mkraljt Tile maps are now available on master if you'd like to try them: https://wasabi2d.readthedocs.io/en/latest/tile_maps.html

lordmauve commented 4 years ago

@robertpfeiffer's original article explains it better than the code linked above: https://blubberquark.tumblr.com/post/185013752945/using-moderngl-for-post-processing-shaders-with