首页 > 解决方案 > How to check if image should be flipped vertically before loading using stb_image

问题描述

I'm writing a project using OpenGL, and loading the textures using stb_image.

Some of the textures are loaded flipped upside down (regarding the y-axis) so I use "stbi flip image vertically on load" to load them properly.

The problem is that some of the textures I load require flipping, and some not, But of course my code flipps them all. how can I check (before loading, or at least before flipping) whether or not to flip the image?

标签: openglstb-image

解决方案


简短的回答:从 stb_image 加载图像到 OpenGL 纹理时总是翻转。更长的答案:您无法知道用户是否想要自己翻转图像。正如提出的那样,我认为您的问题已由Kai Burjack 链接到的问题(我是否应该垂直翻转加载了 stb_image 以在 OpenGL 中使用的图像的线条?)回答了您的问题,因为它阐明了 stb_image 的此功能的正确使用。

如果您直接从图像文件转到 OpenGL 纹理,那么如果您希望导入的纹理的“向上”与用户在其艺术程序中看到的内容相匹配,则应始终在导入期间翻转。但是,如果您想让用户选择将图像倒置加载,而与图像在艺术程序中的外观无关,您也完全可以做到这一点。问题是用户必须告诉你。没有办法知道用户想要什么,而且想要颠倒图像的 IMO 艺术家很可能只是在他们的艺术程序中以这种方式制作它们。


推荐阅读