使用 Pyglet 进行 OpenGL 拾取

发布于 2024-08-02 12:53:03 字数 749 浏览 7 评论 0原文

我正在尝试使用 Pyglet 的 OpenGL 包装器实现选取,但在转换 C 教程< /a> 到 Python。具体如下部分。

#define BUFSIZE 512
GLuint selectBuf[BUFSIZE]

void startPicking(int cursorX, int cursorY) {
    GLint viewport[4];

    glSelectBuffer(BUFSIZE,selectBuf);
    glRenderMode(GL_SELECT);

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();

    glGetIntegerv(GL_VIEWPORT,viewport);
    gluPickMatrix(cursorX,viewport[3]-cursorY,
            5,5,viewport);
    gluPerspective(45,ratio,0.1,1000);
    glMatrixMode(GL_MODELVIEW);
    glInitNames();
}

我不知道如何转声明 GLuint 或 GLint 数组,以便 glSelectBuffer 和 glPickMatrix 工作。有谁知道如何使用 Pyglet 在 Python 中做到这一点?谢谢。

I'm trying to implement picking using Pyglet's OpenGL wrapper, but I'm having trouble converting a C tutorial to Python. Specifically the part below.

#define BUFSIZE 512
GLuint selectBuf[BUFSIZE]

void startPicking(int cursorX, int cursorY) {
    GLint viewport[4];

    glSelectBuffer(BUFSIZE,selectBuf);
    glRenderMode(GL_SELECT);

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();

    glGetIntegerv(GL_VIEWPORT,viewport);
    gluPickMatrix(cursorX,viewport[3]-cursorY,
            5,5,viewport);
    gluPerspective(45,ratio,0.1,1000);
    glMatrixMode(GL_MODELVIEW);
    glInitNames();
}

I'm not sure how to turn declare arrays of GLuint or GLint such that glSelectBuffer and glPickMatrix work. Does anyone know how to do this in Python with Pyglet? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

朮生 2024-08-09 12:53:04

我还没有尝试过你的特定示例,但声明数组的正常方法是在 ctypes 文档中。本质上你会创建一个像这样的数组类型:

FourGLints = GLint * 4
viewport = FourGLints(0, 1, 2, 3)

I haven't tried your particular example, but the normal way to declare arrays is in the ctypes documentation. Essentially you would create an array type like this:

FourGLints = GLint * 4
viewport = FourGLints(0, 1, 2, 3)
吃兔兔 2024-08-09 12:53:04

我在 PyOpenGL 方面运气很好。

http://pyopengl.sourceforge.net/

这非常简单,使用 C 教程会更容易它,我相信。

I've had good luck with PyOpenGL.

http://pyopengl.sourceforge.net/

It's pretty straightforward, and using a C tutorial would be easier with it, I believe.

时光磨忆 2024-08-09 12:53:04

您究竟遇到了什么样的麻烦? Pyglet 的 OpenGL 实现是对 DLL 的薄包装,并且几乎一对一地映射 C 调用。很难想象还有任何其他库可以更好地遵循 C 教程。

例如,此介绍与 C 语言的等效内容几乎相同OpenGL 调用:

from pyglet.gl import *

# Direct OpenGL commands to this window.
window = pyglet.window.Window()

@window.event
def on_draw():
    glClear(GL_COLOR_BUFFER_BIT)
    glLoadIdentity()
    glBegin(GL_TRIANGLES)
    glVertex2f(0, 0)
    glVertex2f(window.width, 0)
    glVertex2f(window.width, window.height)
    glEnd()

pyglet.app.run()

Exactly what sort of trouble are you having? Pyglet's OpenGL implementation is a thin wrapper over the DLL and pretty much maps the C calls one-for-one. It's hard to imagine there would be any other library that could be better in terms of following a C tutorial.

For example, this introduction is pretty much identical to the C equivalent when it comes to the OpenGL calls:

from pyglet.gl import *

# Direct OpenGL commands to this window.
window = pyglet.window.Window()

@window.event
def on_draw():
    glClear(GL_COLOR_BUFFER_BIT)
    glLoadIdentity()
    glBegin(GL_TRIANGLES)
    glVertex2f(0, 0)
    glVertex2f(window.width, 0)
    glVertex2f(window.width, window.height)
    glEnd()

pyglet.app.run()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文