Reputation: 844
I am trying to load a 3x10 image, using only 1 byte per "pixel". This pixel is a single alpha.
When i load the image as follows, every fourth pixel is discarded for some reason. No opengl errors, I have non-power of 2 hardware support.
So if i have the following pixel buffer: { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, the image will look like this:
0 1 2
4 5 6
8 9 10
...
Texture load code:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA8, 3, 10, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels);
I'm not really sure what is happening, I am stumped. Is there anything that can be causing such behavior? I have the latest opengl drivers as well...
Upvotes: 1
Views: 220
Reputation: 54602
The GL_UNPACK_ALIGNMENT
pixel storage value controls row alignment of the texture data passed to glTexImage2D()
. The default value is 4.
Since your data has 3 bytes per row, this will be rounded up to the next multiple of 4, which is 4. So with the default value, glTexImage2D()
will read 4 bytes per row.
To make this work, the row alignment value has to be changed to 1:
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
Upvotes: 2