# How does Blender Autodetect Texture Culture?

I just asked(and found a solution) to a question here, which talks about how I encountered a texturing problem with my own Wavefront Model Parser. The problem was that some models that I was loading would be textured just fine, like models from Legend of Zelda. While other models would not be textured correctly, like Claptrap from borderlands. As it turns out, the issue was not with my parser, but due to the fact that those two models were crafted for two different API's. Nintendo uses OpenGL for Zelda/All Nintendo DS games. While DirectX is used for Borderlands. Why was this a problem? Well, OpenGL and DirectX have different texture-origins. OpenGL has its texture origin at the bottom left hand corner, while DirectX is top-left hand corner. In order to get my texture for Claptrap to render correctly I had to open the diffuse texture up in gimp and flip it vertically, thus inverting it for use with OpenGL.

This led me to an interesting question. I had opened both models in Blender before sending them into my own program. And Blender correctly textured them both. So how does Blender know which culture(OpenGL or DirectX) to use when attempting to texture a model?

I should also mention that both Models were in .obj format. The only difference is that one was created for OpenGL UV's in mind, while the other was DirectX UV's. I want to know how Blender decides which UV format/culture the .obj uses.

• I think Blender doesn't know that and afaik uses OpenGL for drawing viewport in particular; so that's why the result is the same for both models. – Mr Zak Nov 2 '15 at 23:49
• @MrZak So how does it know to flip the DirectX texture coordinates if that is the case? Both of the models I used were in .obj format, so it's not the model format that it detects. – Krythic Nov 2 '15 at 23:51
• Did you try to see these models' textures drawn in programs which use DirectX for redrawing(like 3DS Max)? It may be some problem of the file format, which flips texture coordinates for some reason. Also look at this thread – Mr Zak Nov 3 '15 at 0:06
• @MrZak I did not. But I used them in my program(Follow the link provided in my OP). Which used OpenGL bottom left 0,0. The DirectX model was incorrectly textured, while the OpenGL one was fine. Once I flipped the DirectX model texture vertically, it worked just fine(because it had been inverted to work with OpenGL). – Krythic Nov 3 '15 at 0:11
• @MrZak I'm actually very excited to figure out how Blender does this. I can't even wrap my head around it because if you flip coordinates (DirectX->OpenGL), you still end up with one being invalid for UV mapping. I don't understand how it knows when to invert and when to ignore inversion of textureCoordinates. – Krythic Nov 3 '15 at 0:18

Blender's probably reading the instructions in the mtl (material library) file that accompanies the obj file.

According to the mtl specifications mtl files can include a parameter (-o) that instructs the program reading the file to reverse the texture's origin in the horizontal (u) or vertical (v) directions:

Quoting from the specification document:

The -o option offsets the position of the texture map on the surface by shifting the position of the map origin. The default is 0, 0, 0.

"u" is the value for the horizontal direction of the texture

"v" is an optional argument. "v" is the value for the vertical direction of the texture.

"w" is an optional argument. "w" is the value used for the depth of a 3D texture.

-o v   # This should reverse the texture's origin in the vertical direction


Open your OBJ's MTL files in a text editor and see if you can find anything that resembles this.

• I didn't give Blender the .mtl, nor was it near the .obj. I already considered that! – Krythic Nov 5 '15 at 15:19
• The mtl doesn't exist? Wonder how blender knew to associate the texture file with the OBJ file. Not sure if the obj can include the mtl inline, but that's worth inspecting. – TLousky Nov 5 '15 at 15:22
• Because I dropped the texture onto the model after it had loaded it. See why this is so odd? – Krythic Nov 5 '15 at 15:23
• There has to be something in the .obj it reads. Or some other weird kungfu it does with the order of the UV coordinates. – Krythic Nov 5 '15 at 15:27
• I'm at work so I can't look at the claptrap .obj. But can -o parameter be declared in the .obj? I will reiterate, the .mtl was not present on the machine when blender loaded the mesh. – Krythic Nov 5 '15 at 15:32