[SOLVED] NPOT texture not working as intended?

Started by obi, January 29, 2016, 01:40:14

Previous topic - Next topic

obi

I have a non power of two texture that works just fine in lwjgl2 but lwjgl3 can't display it correctly.

I ran it it with this code under lwjgl3
https://github.com/LWJGL/lwjgl3/blob/master/modules/core/src/test/java/org/lwjgl/demo/stb/Image.java

I have also loaded the image with TWL's PNGDecoder with the same output result.

I have attached the original image and the output from running it in lwjgl3.

spasi

There's nothing wrong with either stb_image or TWL's PNGDecoder. The problem is OpenGL's GL_UNPACK_ALIGNMENT which defaults to 4 bytes. The image you're testing has a stride of 342 * 3 = 1026 bytes, which is not a multiple of 4. Run this:

glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // 2 will work too

before uploading the texture data and it should be fine.

obi

Ah. Think I have to read up on pixel transfers. Guess I was lucky that same code worked under lwjgl2 :)
Since I give both format, internal_format and type I thought glTexImage2D would understand how to transfer the data.

My guess is that the TWL gui library I used with lwjgl2 did set the above alignment and that I got away with it.

Thanks.