   Image Data endianess
  I'm using OpenGL to work with some black and white type images, each with 2 bytes per pixel.  They appear upside down on my big-endian Mac, but ok on my PC.  So the trouble is obviously endianess.They are stored in an array like this:Quote:char *data = new char[height * width * 2];I've tried multiple ways to swap them, like this:char *big_tex_bytes = new char[num_tex_bytes];int jj, ii;for (jj = 0, ii = num_tex_bytes; jj < num_tex_bytes; jj+=2, ii-=2) {big_tex_bytes[jj] = tex_bytes[ii];big_tex_bytes[jj + 1] = tex_bytes[ii - 1];}for (int hh = 0; hh < num_tex_bytes; hh++) {tex_bytes[hh] = big_tex_bytes[hh];}delete big_tex_bytes;Which just swaps every pixel with the opposite one.  The result was this:http://homepage.mac.com/gareth.cross/eh2.png (The original image had the word "Howdy!" in it.)I then realized that all I had to do was swap the rows (lines of pixels going accross the screen), so I wrote this code:char *big_tex_bytes = new char[num_tex_bytes];int bytes_per_row = tex_width * 2;int rowCounter = 1;int backRowCounter = tex_height;int colCounter;for (/**/; rowCounter < tex_height; rowCounter++, backRowCounter--) {for (colCounter = 1; colCounter < bytes_per_row; colCounter++) {big_tex_bytes[backRowCounter * colCounter] = tex_bytes[rowCounter * colCounter];}}for (int t_counter = 0; t_counter < num_tex_bytes; t_counter++) {tex_bytes[t_counter] = big_tex_bytes[t_counter];}That resulted in this:http://homepage.mac.com/gareth.cross/eh1.pngAnd although that's cool, it's not what I'm looking for.  What would you do?Thanks!   
  I'd try looking up htons() and and ntohs() for swapping endianness of short integers in C/C++.   ;  The image being upside down has nothing to do with endianess.  Some image formats store the image upside down (bmp,  some tga).  You will have to flip them to display correctly.  Probably worked on your PC since what you were displaying assumed it was fliped.Your first example seems to try to reverse the bytes of the image but using char pointers for short data means your effectively skipping 1/2 the bytes.  In any case simply reversing the bytes of the image will not work properly.changing endian means byte swapping of 2 & 4 byte integers.  hton and ntoh functions are used in networking for that purpose.  For graphics each pixel or possibly each color element of each pixel will need to be swapped if you have an endian issue.your second example is closer to what you want to do but your not calculating your offsets into the images correctly.  Each line starts at  (line number) * (size of line)  from there you need to copy each pixel of that line, which will be   texture[ line *size + pixel ]   this is assuming your texture is an array of proper type.   If your pixel size is bigger than 1 byte than your arrays & pointers to pixels need to match your pixel size (uint16, uint32, etc).  Other wise you have to worry about copying/manipulating the correct number of bytes.  If you have an RGB 3 byte format you will have to that format manually as there is no uint24   =)hope this helps some   ;  0) Not endianness, for the reasons mark_dev pointed out.1) 2 bytes per pixel, for a black and white image? 65536 levels of grey? O_O   ;  Sorry it took me so long to get back to this thread guys/gals!I meant 2 bytes as it *two* chars allocated for every pixel.  But now that I've thought about it I've realized that chars have no endianess. *duh* :pIt looks like I'm gonna have to work 180? flip code into all the OpenGL drawing commands.  This will be difficult as the texture may be drawn after previous transformations.  And that will hurt performance greatly too.  I have no way of flipping the textures before-hand, unfortunatly.I've noticed that sometimes swapping the order of OpenGL texture coordinates fixes this, I could do that* during the load...Thanks!   