Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL texture tilted

When I load a texture in OpenGL and this has one (GL_ALPHA) or three components per pixel (GL_RGB), the texture appears tilted. What makes this happen?

As additional detail, the relation width/height seems to affect. For example, an image of 1366x768(683/384) appears tilted while an image of 1920x1080(16/9) is mapped correctly.

slanted image

like image 677
Robert Rojas Avatar asked Apr 13 '13 02:04

Robert Rojas


1 Answers

This is probably a padding/alignment issue.

GL, by default, expects rows of pixels to be padded to a multiple of 4 bytes. A 1366 wide texture with 1 byte or 3 byte wide pixels, will not be naturally 4 byte aligned.

Possible fixes for this are:

  • Tell GL how your texture is packed, using (for example) glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  • Change the dimensions of your texture, such that the padding matches without changing anything
  • Change the loading of your texture, such that the padding is consistent with what GL expects
like image 99
JasonD Avatar answered Sep 21 '22 04:09

JasonD