Skip to content
Advertisement

pyOpenGL 2D Image drawn skewed

I am trying to draw a 2d image in OpenGL using pillow to load the image, but when I render it in OpenGL, the image is skewed.

This is the original image:

Loading.png

enter image description here

This is the code:

JavaScript

Result

enter image description here

As you can see, the result is a skewed image, I don’t know why this is happening, and I can’t see the problem with the code.

edit: can confirm same problem in python 2.7 and 3.8

Advertisement

Answer

When the image is loaded to a texture object, then GL_UNPACK_ALIGNMENT has to be set to 1:

JavaScript

Note, in your case the alignment is set to 4 (what is defualt). This means that each line of the image is assumed to be aligned to a size which is a multiple of 4. Since the image data are tightly packed and each pixel has a size of 3 bytes (GL_RGB), the alignment has to be changed.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement