0

I am having a texture issue that has me stumped.

I'm building an OpenGL renderer with which I've loaded and rendered several models and textures from multiple sources.... all worked as expected. Then I generated a terrain using WorldMachine. I exported an OBJ with a diffuse texture. For some reason that world machine generated texture renders incorrectly. This is what its supposed to look like.

enter image description here

When I load it onto it's model in my renderer it looks like this:

enter image description here

Stealing a texture from another model that's loading and rendering correctly and applying it to this terrain model it looks like it renders correctly.

enter image description here

I'm using stb image loader. The terrain texture seems to load correctly. STB reports that both have 3 channels....

I'm at a loss. It seems like its an issue with the texture its self but I have no idea what it could be. The terrain texture is 1025x1025, the one that works is 4096x4096. Reading here confirms that modern hardware shouldn't have issues with non power of two textures so I don't think that's it. I don't know a huge amount about texture formats (jpg/png) is there some rgb ordering or bit size considerations that I need to be aware of?

Does anyone know why this might happen?

Nick
  • 862
  • 12
  • 35
  • Your 1025x1025 texture stride is not divisible by 4, whereas 4096x4096 is. You need to set `GL_UNPACK_ALIGNMENT` to `1` as described in the linked question. – Yakov Galka Jan 24 '21 at 05:25
  • Ah, interesting reading. I wasn't aware of the required channels param in stbi_load. I tried setting it to 4 then set my glTexImage2D formats both to RGBA and it worked! Thank you. If you want to summarize any of this into an answer I will mark it as accepted. – Nick Jan 24 '21 at 06:03

0 Answers0