1

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?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
hannak
  • 11
  • 1
  • 4
    I don't understand. You should already know which images need to be flipped, it's your rendering code after all. – HolyBlackCat Sep 12 '21 at 15:23
  • OpenGL expects the 0.0 coordinate on the y-axis to be on the bottom side of the image, but images sometimes have 0.0 at the top of the y-axis. What I'm asking is, how do I know if a specific texture that I want to load (some texture I've found on the net) has its 0.0 coardinate in the top or in the bottom of the y-axis. – hannak Sep 12 '21 at 15:50
  • I want to give the user option to load his own models (that I won't be familiar with) so I want to check in my program whether or not I should flip his texture. Hope it's more clear now and thank you for the comment! – hannak Sep 12 '21 at 15:53
  • No :( there they don't answer my question, which is how do I know *before* loading if a texture should be flipped. – hannak Sep 12 '21 at 16:09
  • @hannak: "*how do I know before loading if a texture should be flipped*" You know *because it's your image*. You are responsible for it. You either created it or got it from somewhere. Either way, you are responsible for its contents, which *includes* its orientation. Looking at them in an image viewer would help. – Nicol Bolas Sep 12 '21 at 16:38
  • I thought like that too, but all the models I loaded via stb_image shouldn't be flipped... I don't know how stb_image is impemented behind the scenes, but that's what I got... I downloaded my textures from free3d.com, maybe they already flip the textures before uploading it to their website? – hannak Sep 12 '21 at 16:41
  • @NicolBolas as I mentioned in previous comments, I want to give a future user option to load a texture I'm unfamiliar with. What I'm asking is, if there is any way I can figure out whether I shouls flip the user's texture or not based on the textures data that is available to me during loading. – hannak Sep 12 '21 at 16:45
  • @hannak: Then it's *their* responsibility to conform to the requirements of your code. One of those requirements is the image's orientation. It's functionally no different from not supporting particular image formats. – Nicol Bolas Sep 12 '21 at 16:52
  • 1
    Just give the user a checkbox to flip the texture. There's no way to automatically determine whether to flip or not. – HolyBlackCat Sep 12 '21 at 16:59
  • @NicolBolas You should not be bringing responsibility into question here. It does nothing but add to the existing lack of clarity with what is being asked. The OP is not on trial, we're not deciding whom to assign blame to. The OP is missing some information, hence their question, and saying that knowing such info is their responsibility does not benefit anyone. I suggest doing something that is constructive for questions like these, such as trying to narrow down why the OP does not know whether an image should be flipped, or anything that can lead to an answer. – Kröw Mar 31 '23 at 07:33
  • @Kröw: "*trying to narrow down why the OP does not know whether an image should be flipped*" But they said why: "I want to give a future user option to load a texture I'm unfamiliar with." That is, the OP is deliberately designing the system *not to know* in order to give users "options". I'm saying that this is the wrong way to design a system. – Nicol Bolas Mar 31 '23 at 13:47

1 Answers1

1

Short answer: always flip when loading an image from stb_image to an OpenGL texture. Longer answer: you can't know whether a user wants to flip the image themselves. As it was posed, I think your question is answered by the question Kai Burjack linked you to (Should I vertically flip the lines of an image loaded with stb_image to use in OpenGL?) because it clarifies the correct use of this feature of stb_image.

If you are going straight from an image file to an OpenGL texture, then you should always flip during import if you want the "up" of the imported texture to match what users see in their art programs. However, if you want to give users the option to load images upside down independent of how the image looks in the art program, you can totally do that, too. The catch is that the user has to tell you. There's no way to know what the user wants, and IMO artists who want their images upside-down are likely to just make them that way in their art programs anyways.