pylab.imshow - how does it work?

Hi,

I have a set of images I want to render with OpenGL, and I do this by
doing some calculations, producing an array, then passing this array
to OpenGL. Here's the relevant OpenGL call, for reference:

gluBuild2DMipmaps(GL_TEXTURE_2D, 1, image.shape[0], image.shape[1],
              GL_LUMINANCE, GL_UNSIGNED_BYTE, flatImage)

flatImage is just image as a flattened, contiguous numpy array... all
that matters is that it contains the same values as in image.

The problem is that passing my arrays to pylab.imshow() displays them
exactly as they are meant to be, but in OpenGL they are 'twisted'.
There is an offset that is _different_ for each picture that only
seems to be resolved by replacing 'image.shape[0]' by
'image.shape[0]-5' or some other numbers that make the rows shorter.
How is it that OpenGL does weird things with the row length but pylab
is always happy?

I can send pictures of the problem if it helps....

Adeola

Hi Adeola,

OpenGL must be expecting a certain "packing" but your image data is packed differently. You have (at least) two options: 1) alter your numpy arrays to match the packing of OpenGL. This can be done by creating an array with the appropriate .strides value. 2) alter OpenGL's idea of how the data is packed. For this, see "7. Watch Your Pixel Store Alignment" in Avoiding 16 Common OpenGL Pitfalls

-Andrew

Adeola Bannis wrote:

···

Hi,

I have a set of images I want to render with OpenGL, and I do this by
doing some calculations, producing an array, then passing this array
to OpenGL. Here's the relevant OpenGL call, for reference:

gluBuild2DMipmaps(GL_TEXTURE_2D, 1, image.shape[0], image.shape[1],
              GL_LUMINANCE, GL_UNSIGNED_BYTE, flatImage)

flatImage is just image as a flattened, contiguous numpy array... all
that matters is that it contains the same values as in image.

The problem is that passing my arrays to pylab.imshow() displays them
exactly as they are meant to be, but in OpenGL they are 'twisted'.
There is an offset that is _different_ for each picture that only
seems to be resolved by replacing 'image.shape[0]' by
'image.shape[0]-5' or some other numbers that make the rows shorter.
How is it that OpenGL does weird things with the row length but pylab
is always happy?

I can send pictures of the problem if it helps....

Adeola

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options