【问题标题】:OpenGL Picking with Pyglet使用 Pyglet 进行 OpenGL 拾取
【发布时间】:2010-11-20 09:19:45
【问题描述】:

我正在尝试使用 Pyglet 的 OpenGL 包装器实现拾取,但在将 C tutorial 转换为 Python 时遇到问题。具体如下部分。

#define BUFSIZE 512
GLuint selectBuf[BUFSIZE]

无效 startPicking(int cursorX,int cursorY){
    GLint视口[4];

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

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

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

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

【问题讨论】:

    标签: python opengl pyglet picking


    【解决方案1】:

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

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

    【讨论】:

    • 这正是我所需要的。感谢您为我指明正确的方向。
    【解决方案2】:

    我在 PyOpenGL 上运气不错。

    http://pyopengl.sourceforge.net/

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

    【讨论】:

      【解决方案3】:

      你到底遇到了什么麻烦? Pyglet 的 OpenGL 实现是对 DLL 的薄包装,并且几乎一对一地映射 C 调用。很难想象在遵循 C 教程方面会有任何其他库更好。

      例如,当涉及到 OpenGL 调用时,this introduction 与 C 等效项几乎相同:

      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()
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-10-04
        相关资源
        最近更新 更多