View Full Version : problems reading FrameBuffer

06-11-2004, 12:20 PM
hello everyone
i have a routine that draws some stuff in a 2d projection and i read the frame buffer to get the image. whatz happening is sometimes it works fine and sometimes it just reads 0s. it alwayz works if i step thru the code in debug mode. any help would be appreciated

glPushAttrib amAllAttribBits
'set projection to 2D othro to draw the vector image overlay and take a snapshot
glMatrixMode mmProjection
gluOrtho2D dblTempXMin, dblTempXMax, dblTempYMin, dblTempYMax

'clear buffers
glClearColor 0, 0, 0, 1
glClear clrColorBufferBit

............... Draw the 2d polygon .....

'read the back buffer
glReadBuffer rbmBack

'set the size
lngSize = CLng(mintWidth) * mintHeight * 4

ReDim sngFrameBuff(lngSize)

'read the contents of the framebuffer
glReadPixels 0, 0, mintWidth, mintHeight, rpRGBA, pxlFloat, sngFrameBuff(0)

'end the OpenGL DL

06-12-2004, 01:05 AM
From the GL spec, readpixels should occur after all drawing commands are actually done. Maybe is it not the case for your graphic card/driver, so put the glFinish before the readpixels call and see if it changes something.

06-15-2004, 12:11 PM
i tried adding glfinish, but it still behaves the same way. usually, it doesnt show up the first time, n shows up the second time. anybody????

06-15-2004, 01:54 PM
Which card/drivers/system ?

And are you sure you read the right buffer ? back, front, swapbuffers, etc. Maybe try with single buffer window, to be sure.

06-16-2004, 06:31 AM
Originally posted by ZbuffeR:
Which card/drivers/system ?

And are you sure you read the right buffer ? back, front, swapbuffers, etc. Maybe try with single buffer window, to be sure.i think im reading the right(back) buffer, cause i read the pixels before i swap the buffers. so i think it should be right. i need to try using a single buffer.
does glfinish swap the buffers?
can i switch from double buffers to single buffer and switch back to double?

thank u

i have an ATI RAEDON IGP 345M
Driver :
Windows XP

my friend has a ATI MOBLILITY RAEDON 9000 and windows XP. on his system, the snapshot that i take is currupted intitially and behaves differently.

06-16-2004, 09:56 AM
you should try glFlush() to ensure all your drawing is done... I'm not sure, but it may be worth trying !

06-16-2004, 12:49 PM
glFlush is weaker than glFinish. It is subtle, but glFinish only return when all the graphics commands have been processed, whereas glFlush just tell the hardware to actually proccess the commands as soon as possible (instead of waiting to fill the commands buffer).

Anyway, the default read buffer is the back buffer if you use double buffering, and readpixels is done after all previous command have been processed, so there should not be any problems about that. Can you simplify enougth the code to post it here completely ?