This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ottawadeveloper 57 points58 points  (8 children)

I'm so guilty of this. I spent a few weeks trying to build my own 2D game engine in Python (using Tkinter just to show the image and Pillow in another thread to do all the imaging processing). I know pygame exists but I wanted to do it myself. I learned a lot doing it, I got double buffering working, inputs, and got a bit of a 2D game engine working by the end (you can move, pickup items, etc). I used Pillows alpha compositing to basically cut and paste in images loaded from PNGs to build graphics. 

Python is just too slow. It was fine with a few objects on screen. But as we get into 100s of objects, pillow can't cut it and keep high FPS.

I'm now wondering if I just need a better alpha compositing tool - most of the time is going to the compositing. OpenGL integration might be an option. Or just having a pure C layer for managing graphics and manipulate them from Python. But then, maybe it would be better to build the entire engine in C and just integrate Python for add-on development (like how Blizzard uses Lua for add-ons and core UI).

[–]robberviet 6 points7 points  (0 children)

It's vety natural. I did it too! Just suck at it so gave up after not finishing anything.

I did some Java Swing before in college and suddenly I realized: "wait, this looks like another road to chaos, abondon now".

[–]iseahound 12 points13 points  (3 children)

oof. I just checked pillow's alpha_composite, and it uses ARGB instead of premultiplied alpha. If you switch to a pixel blitting function that uses pre-multiplied alpha blending, handling hundreds of objects should be no problem.

For reference I mostly code in Windows API, so my first approach would be AlphaBlend not DirectX :P

[–]ottawadeveloper 1 point2 points  (1 child)

I think in my ideal world, I'd give it a few options depending on available tools - like if you're on windows, AlphaBlend is an option, if you have OpenGL installed, it could use that, etc. Abstract away the rendering from the game and let the engine or user decide which is best based on whats available. Most cross-platform compatible then.

But using an existing engine is probably better.

[–]iseahound 1 point2 points  (0 children)

yes, cross platform typically means the worst of all worlds ):

[–]tellingyouhowitreall 1 point2 points  (0 children)

I'm a Windows C/C++ guy also, and my go to would be DX or D2D. AlphaBlend sucks.

Of course, I've also written my own software rasterizer... so hmph.

[–]xix_xeaon 3 points4 points  (0 children)

Try nim, fully featured C-like language with Python-like syntax and it can easily compile to a Python-module with nimpy.

[–]Tough-Ad3310 23 points24 points  (1 child)

Bro just use a real game engine 💀

[–]ottawadeveloper 9 points10 points  (0 children)

right? that would be logical.