Recommended Posts

I recently developed a need for an off-screen buffer so I could render images via a command line tool that would not be able to produce a window for rendering. I looked up the needed code changes (PFD_DRAW_TO_BITMAP in Windows, for example), but it didn't seem to be working right.
I eventually tripped over glFlush() and looked up why that made things work. I had no idea that OpenGL commands are actually buffered and processed via means unknown at appropriate times like when the system's SwapBuffers or equivalent are called. I simply assumed that if I send a command, it gets executed and I have my pixels in my memory buffer. Well, that's not the case.
So to prevent someone else from losing a portion of their hair when working with single-buffered, non-windowed OpenGL contexts: remember to use glFlush() to make sure everything's taken care of and all pixels are rendered!

0

Share this post

Link to post

Share on other sites

Original post by GuyPerfectSo to prevent someone else from losing a portion of their hair when working with single-buffered, non-windowed OpenGL contexts: remember to use glFlush() to make sure everything's taken care of and all pixels are rendered!

Be careful, glFlush doesn't do what you think it is doing ! glFlush will only initiate a flush of the command buffer to the GPU, but it will not wait for it to complete. So you are still not guaranteed that all pixels are in fact rendered after issuing this command. That it is working for you right now could just be a timing coincidence.

What you are looking for is glFinish(). It does basically the same as glFlush, but it will wait until all rendering operations are really completed.

Share this post

Link to post

Share on other sites

If you're planning on doing some fairly CPU intensive work while rendering stuff, you can make all of the rendering calls, then call glFlush() to start the rendering, and then begin the other work, and once that's done, you can then swap the buffers, or call glFinish() (depending on what you're doing...). That's the way I do things anyway... It works in theory, and I haven't had any problems with it, so I assume it'd be the best way to go about things...