Jump to content
  • Advertisement
Sign in to follow this  

OpenGL OpenGL UV Mapping and FBX Loading

This topic is 2036 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm reading the FBX file format and getting the UVs from the models, but I'm having weird issues with the UV Mapping from the textures.


Also, I'm using the sbti_image loader to load a PNG file, not sure if it's relevant (I think it reverses the pixels but I think that's common for all image types).


So, when I load a 2D Image, using a texture I have the image mirrored both in horizontal and vertical. That was fine if I just reversed the positions and mirror the texture, but that only works when the texture is full. I didn't want to keep that as a "fix" so I tried to get the correct orientation from the FBX and apply it properly.


The 2nd image is how it is in the 3DS Max, in the first image is how my engine is displaying it.




I'm reversing the V component so the texture is at least correct vertically:

for(int i = 0; i < totaUVs; i++)
    float u = UVs[uIndex];
    float v = UVs[uIndex + 1];
    UVs[uIndex] = u;
    UVs[uIndex + 1] = 1.0f - v;			

If I don't do this, the image is also mirrored upside down.

The "1.0f - v" part is correcting the V part, but the U is still incorrectly mapped. I can't do "1.0f - u" because then the U part would be reversed in the image, so in an image of 200 pixels width, a U part of 10 would be 190, meaning it works if the image is full (100% width and 100% height) but not when I'm using a mapped texture like this.


How can I solve this?

I'm thinking in reversing the pixels in my image data but if possible I'd like to find a "smarter" solution, any help with this?

Share this post

Link to post
Share on other sites

Another example, probably better explained:



The 3DS Max vertex data is upside down in my engine, and I'm guessing it's because the XYZ values in 3DS Max are left handed, and OpenGL is right handed right?

That's manageable, but the UV data is messed around too, and I noticed that the way I was even going on about mirroring textures is wrong because I was assuming a texture that covers the entire image, not just part of it.


I'm meaning that, in the example above, if I only put some texture color in the Purple area, and I mirror it horizontally with my current code, I'm just picking the UV values that correspond to the Red area in the texture, and that's wrong... I made this assuming 2D images and square textures and now that I'm loading directly from the FBX, it's not working for 3D models.


Using "1.0f - uv" values work for 2D planes, but not for 3D models...

Edited by Danicco

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!