Jump to content

  • Log In with Google      Sign In   
  • Create Account


b1narez

Member Since 05 Nov 2013
Offline Last Active Jan 25 2014 11:45 AM
-----

Posts I've Made

In Topic: Should I vertically flip the lines of an image loaded with stb_image to use i...

05 November 2013 - 10:58 AM

Yeah, (S,-T) would only work for wrapping texture mode I think. Like I said in my answer, I'll be flipping vertically the image at load time and see if it's a problem down the road. If it is, I'll probably just do (S, 1.0 - T) in my GLSL vertex shader. I want to keep my common code as portable as possible. Thanks 3TATUK2 for your replies!


In Topic: Should I vertically flip the lines of an image loaded with stb_image to use i...

05 November 2013 - 08:56 AM

Ok, I will answer my own question... I went thru the documentation for both libs (stb_image and OpenGL).

 

Here are the appropriate bits with reference:

 

glTexImage2D says the following about the data pointer parameter: "The first element corresponds to the lower left corner of the texture image. Subsequent elements progress left-to-right through the remaining texels in the lowest row of the texture image, and then in successively higher rows of the texture image. The final element corresponds to the upper right corner of the texture image." From http://www.opengl.org/sdk/docs/man/xhtml/glTexImage2D.xml

 

The stb_image lib says this about the loaded image pixel: "The return value from an image loader is an 'unsigned char *' which points to the pixel data. The pixel data consists of *y scanlines of *x pixels, with each pixel consisting of N interleaved 8-bit components; the first pixel pointed to is top-left-most in the image." From http://nothings.org/stb_image.c

 

So, the issue is related the pixel storage difference between the image loading lib and OpenGL. It wouldn't matter if I loaded other file formats than PNG because stb_image returns the same data pointer for all formats it loads.

 

So I decided I'll just swap in place the pixel data returned by stb_image in my OglTextureFactory. This way, I keep my approach platform-independent. If load time becomes an issue down the road, I'll remove the flipping at load time and do something on the GPU instead.

 

Hope this helps someone else in the future.

 

This topic was originally a StackOverflow question that I couldn't get a good answer for: http://stackoverflow.com/questions/19770296/should-i-vertically-flip-the-lines-of-an-image-loaded-with-stb-image-to-use-in-o


PARTNERS