Topic Options
Rate This Topic
#235726 - 03/15/08 08:15 PM How to flip color buffer during/before glReadPixel
Duncan Champney Offline
Contributor

Registered: 03/15/08
Posts: 83
Loc: Northern Virginia (USA)
I'm adding a file save feature to my app that takes a snapshot of a 3D view and saves it to disk as a TIFF or JPEG.

I use glReadPixels to copy the pixel data from a framebuffer object to a data structure in main memory.

Unfortunately, pixel data is stored with 0,0 at the top left on my platform (Mac OS X). Thus, the image winds up flipped vertically once it winds up in main memory.

I could flip it in main memory by re-drawing it from one bitmap structure (actually an NSBitmapImageRep) to another, but the image is potentially huge (8000x8000 pixels or bigger) and I'd rather not create yet another copy of it if I can avoid it. I guess I could also write code that would line-by-line flip every scan line while only saving one scan line to temporary memory.

My preference, though, would be to have OpenGL either render the image flipped, or flip it as it copies it to main memory. I tried using glPixelZoom, but apparently that only affects glDrawPixels, not glReadPixels.

A transformation matrix won't work (I don't think) because this is a 2D flip of my scene after it's been rendered to the pixel buffer, with lighting, projection, etc, etc.

I assume there is some fairly simple way to do this, but what is it? I guess I could use glPixelZoom plus glDrawPixels to copy and invert the contents of the front buffer to the back buffer, then use glReadPixels to copy the back buffer to main memory. Is there a cleaner way, however?


Duncan C
_________________________
Duncan C

Top
#235728 - 03/16/08 01:23 AM Re: How to flip color buffer during/before glReadPixel [Re: Duncan Champney]
sqrt[-1] Offline
Frequent Contributor
*****

Registered: 06/05/02
Posts: 936
Loc: Australia
I would just do the "write code that would line-by-line flip every scan line while only saving one scan line to temporary memory." - any other way is probably going to cause OpenGL to allocate a large buffer to do the flip in.

The other options are to redraw the scene upside down just before you save, or save in a bitmap format that has a flag indicating the orientation of the bitmap data. (I believe TGA has this flag, not sure about other formats)

From wikipedia : http://www.gamers.org/dEngine/quake3/TGA.txt

Top


Moderator:  barthold, dorbie, ZbuffeR, Zengar 
Search

Who's Online
7 registered (Dark Photon, ZbuffeR, skynet, kikoST, pjcozzi, johan.schmidt, laobrasuca), 28 Guests and 11 Spiders online.
Key: Admin, Global Mod, Mod
Newest Members
johan.schmidt, dianazubiri, jamec9869, Rustang, KylBlz
26019 Registered Users
Top Posters (30 Days)
Alfonse Reinheart 103
Dark Photon 85
ZbuffeR 77
ugluk 51
BionicBytes 41
DmitryM 40
nickels 30
david_f_knight 29
mhagain 28
Rosario Leonardi 28
Aleksandar 27
Mr.Byteside 23
Groovounet 20
Schnulla 19
jenny_wui 17
thinks 15
somboon 15
trinitrotoluene 13
glSun 13
kyle_ 12
Forum Stats
26020 Members
13 Forums
54469 Topics
282446 Posts

Max Online: 482 @ 08/11/08 06:19 PM