OpenGL 与 Python
我目前正在学习使用 OpenGL 的课程,到目前为止我一直在使用 C 语言编写所有程序。 我在 Fedora 上安装了 Python 以及 OpenGL,但是当我在 Python 代码中调用 OpenGL 命令时,我遇到了分段错误。 我不知道这是为什么。
为了避免“只使用 C”评论,这就是我想使用 Python 的原因:
我想从 C 切换到 Python 有几个原因,但最主要的一个是因为我们即将开始编写光线跟踪器,并且我想使用课程来让我更轻松。 因为我讨厌 C++ 中的类,而 C 中的结构似乎有点疯狂,所以我想我应该尝试一下 Python。 我也一直在寻找再次使用 Python 的理由,因为已经有一段时间了。
谢谢你的帮助。
I am currently in a course that is using OpenGL and I have been using C for all the programs so far. I have Python installed on Fedora as well as OpenGL, however the minute I call an OpenGL command in my Python code, I get a segmentation fault. I have no idea why this is.
Just to avoid the "just use C" comments, here is why I want to use Python:
There are a couple reasons I am wanting to switch from C to Python, but the main one is because we are about to start writing a raytracer and I would like to use classes to make it easier on me. Since I hate classes in C++ and structs in C seems a little crazy, I thought I would give Python a try at it. I have also been looking for a reason to use Python again as it has been a while.
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可能还需要考虑使用 Pyglet 而不是 PyOpenGL。 它是本地平台上原生 OpenGL 库的 ctypes 包装器,以及窗口支持(应该处理您想要使用 GLUT 的大部分内容。) pyglet-users 列表非常活跃并且非常有帮助。
You may also want to consider using Pyglet instead of PyOpenGL. It's a ctypes-wrapper around the native OpenGL libs on the local platform, along with windowing support (should handle most of the stuff you want to use GLUT for.) The pyglet-users list is pretty active and very helpful.
好吧,我不知道这些是否是原始海报使用的库,但我在我正在使用 PyOpenGL 开发的宠物项目(使用 C++ 和 Python 的图形引擎)中看到了相同的问题。
如果 PyOpenGL 是在加载 python 脚本之后创建的,则无法正确获取渲染上下文(我首先加载脚本,然后从 C++ 代码中调用其中的 Python 方法)。
如果在加载 Python 脚本之前初始化显示并创建 OpenGL 渲染上下文,则不会出现该问题。
Well, I don't know if these are the libs the original poster are using but I saw identical issues in a pet project I'm working on (Graphics Engine using C++ and Python) using PyOpenGL.
PyOpenGL didn't correctly pick up the rendering context if it was created after the python script had been loaded (I was loading the script first, then calling Python methods in it from my C++ code).
The problem doesn't appear if you initialize the display and create the OpenGL rendering context before loading the Python script.
您使用什么 OpenGL 库? 什么窗口库? 什么版本的Python?
我能想到的最可能的原因是您的窗口库(SDL 或您正在使用的任何库)在开始调用 OpenGL 之前没有初始化它。
What OpenGL library are you using? What windowing library? What version of Python?
Most likely cause I can think of is that your windowing library (SDL or whatever you're using) isn't initializing OpenGL before you start calling into it.
我们对随机分割错误一无所知。 没有足够的信息。 opengl 使用哪些 python 库? 你如何使用它们? 您能向我们展示您的代码吗? 这可能是一些微不足道的事情,但我的神技最终只告诉我这一点。
python 中的光线追踪器? 我更喜欢在 C 中使用这些结构来做到这一点。 但是,我假设你不会做实时光线追踪器,所以这可能没问题。
We have neither ideas about random segmentation faults. There is not enough information. What python libraries are you using for opengl? How do you use them? Can you show us your code? It's probably something trivial but my god -skill ends up to telling me just and only that.
Raytracer in python? I'd prefer just doing that in C with those structs. But then, I'm assuming you aren't going to do a realtime raytracer so that may be ok.
也许您正在调用一个需要活动 OpenGL 上下文的 OpenGL 函数,但实际上却没有? 这不一定会崩溃,但我想可能会崩溃。 如何设置这样的上下文取决于平台,自从我使用Python中的GL以来已经有一段时间了(当我使用GL时,我还使用了GTK+,这使事情变得复杂)。
Perhaps you are calling an OpenGL function that requires an active OpenGL context, without having one? That shouldn't necessarily crash, but I guess it might. How to set up such a context depends on the platform, and it's been a while since I used GL from Python (and when I did, I also used GTK+ which complicates matters).
脚本永远不会导致分段错误。
但首先看看你的内核和 kmod 视频驱动程序是否工作正常......
扩展模块可能会导致“分段错误”。
Scripts never cause segmentation faults.
But first see if your kernel and kmod video driver working property ...
Extension modules can cause "segmentation fault".