tags:

views:

38

answers:

2

I have the data of an image loaded into memory as a one dimensional array. Since I'm trying to use OpenGL to draw it, and since it reads from the bottom up, I want to try and flip the elements of the array before they're sent to OpenGL. Maybe there's a way to tell OpenGL to read from the top to the bottom? Anyways, I tried using a few methods of sorting arrays and they also flip the image horizontally, which is very much like the original problem. So can I flip the data only one way?

+4  A: 

So can I flip the data only one way?

Yes, you can.
1D array of pixels is made of image_height blocks of image_width pixels. One image_width block is a scanline or a row of pixels. Scanlines go in sequental order. The last scanline starts at [array_size - image_width], one before last is [array_size - image_width*2] and so on . The first scanline starts at index zero, second - at [image_width], thifrd at [image_width*2] so on. To flip, you must exchange data in last scanline with first scanline and keep going this way.

Maybe there's a way to tell OpenGL to read from the top to the bottom?

No, but you can flip texture coordinates on the mesh/geometry you draw.

P.S. Is it really that hard to figure out? You could easily guess solution with pen/paper.

SigTerm
+1 for the P.S. And for the solution, too :)
Julien L.
Thanks, I actually was able to solve this by using glPixelZoom, but I agree that if I had chosen to visualize the memory, it would have been simple to solve.
Jeff
A: 

As SigTerm stated the easiest way would be to flip the texturecoords.

just when your rendering the object flip the coords that your are calling with glTexCoord2f(). simple just negate the width.

Ben E