Search code examples
pythonopenglpygletpicking

OpenGL Picking with Pyglet


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.


Solution

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