带有 Python 绑定的 C lib,两者都想要渲染
我正在用 Python 绘制一些流体动力学草图。一段时间后,我寻求更快的速度,因此我用 C 重写了实际逻辑并设置了一些 Python 绑定(使用 SWIG)。
我现在的问题是我不知道如何以好的方式渲染它。逻辑是逐像素运行的,因此像素就是我想要跟踪和渲染的内容。
如果我尝试在 C 库中创建一个接受 SDL_Surface*
的函数,Python 会给我一个 TypeError ,我可能有点天真地认为 PyGame 可以轻松地直接映射到 SDL。 Python 似乎也不确定如果我让 C 库“init”返回 SDL_Surface*
该怎么办。
有什么好的方法可以做到这一点?如果我只渲染 C 库中的所有内容,那不会有问题。但我想在那里放置一些 GUI(使用 Python)。 C lib 已经记录了哪些像素是“脏”的。我应该公开该列表并让Python循环遍历它,为每个脏像素调用一个函数吗?看起来很糟糕,因为这些巨大的循环正是我想用 C 重写应用程序部分的确切原因。
在有人提出建议之前, boost.python 现在安装起来有点繁重(因为我使用的是 Windows),所以我暂时只使用 SWIG(除非有人有聪明的方法来安装“仅”boost.python?)。
我希望这里能有灵丹妙药。 如何制作 C 库、运行 SDL、与 Python 共享渲染目标、运行 PyGame?
I'm sketching on some fluid dynamics in Python. After a while, I'm looking for a bit more speed, so I rewrote the actual logic in C and put up some Python bindings (using SWIG).
My problem now is that I don't how to render it in a good way. The logic is run pixel by pixel so pixels are what I want to track and render.
Python gives my a TypeError if I try to make a function in the C lib that accepts a SDL_Surface*
, I was probably a bit naive to think that PyGame mapped that easily directly to SDL. Python also seems unsure what to do if I make the C libs "init" return an SDL_Surface*
.
What is a good way to do this? It wouldn't be a problem if I would just render everything in the C lib. But I want to put on some GUI there (using Python). The C lib already keeps track of which pixels are "dirty". Should I expose that list and let Python loop through it, call a function for every dirty pixel? Seems bad, since those kind of huge loops are the exact reason I wanted to rewrite parts of the app in C.
And before anyone suggests it, boost.python is a bit heavy to install right now (since I'm on Windows), so I'll just stick to SWIG for the moment (unless anyone has a clever way to install "just" boost.python?).
I'm hoping for a silver bullet here. How to make a C lib, running SDL, share a render target with Python, running PyGame?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过类似下面的方法从 python 对象获取
SDL_Surface*
?Have you tried something like the following to get
SDL_Surface*
from python object?