Search code examples
pythonopenglpyopengl

glReadPixels returning different data types in Python


I am using working with OpenGL via Python 3.6 / PyOpenGL 3.1.0 in Ubuntu on two different machines with the same configuration (unless there is something I am missing).

I'm running the same script on both machines.

Code goes like that:

    pixels = glReadPixels(0, 0, 640, 640, GL_RGB, GL_FLOAT)
    print(pixels)

On one machine the print displays:

<OpenGL.arrays.ctypesarrays.c_float_Array_640_Array_640_Array_3 object at 0x7fcd1e681158>

whereas on the other I get an array of floats, as expected:

[[[0. 0. 0.]
  [0. 0. 0.]
  [0. 0. 0.]
  ...

What do you think about this? Thank you.


Solution

  • Following Joe's advice, I tried print(type(pixels)) and found:

    <class 'numpy.ndarray'> on the machine that printed nice-looking matrices

    vs

    <OpenGL.arrays.ctypesarrays. ...> on the other one.

    It turned out that the second machine missed numpy. After installing numpy, the result was identical to that obtained on the first machine.

    This had been especially annoying since the script second machine crashed when trying to serialize the data with pickle.

    Leaving this answer here in the hope that others might find it useful.