PDA

View Full Version : Double Buffering in OpenGL on top of GDI



ns12345
06-06-2010, 03:17 AM
Hi,

I am a total beginner to OpenGL and I have a question please.

I have an MFC application that has a lot of drawing using GDI. The rendering is getting heavy as I the number of shapes being drawn is relatively huge. I thought of migrating to OpenGL to fasten it a bit. Unfortunately, I cannot migrate the whole application at once, so I planning to make it incrementally.

Let's assume I do the following in the OnPaint event handler:
DrawX()
DrawY()
DrawZ()

I want to migrate DrawY for the time being and use OpenGL instead. I was able to convert all the drawing in it to be in OpenGL, but the problem now is integrating it in my code.

In DrawY (with OpenGL), I used double buffering (to maximize the speed) and at the end of drawing I called SwapBuffers to get the cached drawing on the screen. So, whatever was drawn in DrawX is erased and replaced by the buffer used in DrawY.

My question is: is there a way to draw on top of what was already drawn without replacing it? I know one way of doing so is simply not using the double buffering, but this way the drawing is slow again.

Please help.
Thanks and sorry for my long post.

ZbuffeR
06-06-2010, 11:30 AM
Mixing GDI and OpenGL on the same surface is not a good idea.

If you really need to migrate your rendering by parts, you need to create "plumbing" between GL and GDI, each drawing to a different surface, for example with an offscreen FBO. But that may be easier to migrate everything to OpenGL, depending of what is in DrawX, DrawZ.

Don't hesitate to continue this thread, posting questions and thoutghs about what you decide to do.

ns12345
06-06-2010, 11:39 PM
Thank you ZbuffeR for your reply :)

Ok let's assume that I will migrate everything to OpenGL, I will still have the same problem if at the end of each Draw function I call SwapBuffers (each call to swap buffers will replace what's on the screen with the new buffer). I cannot call swap buffers just once at the very end of all the drawing as I need to let the user feel that the drawing is being done incrementally.

Thank you.

ZbuffeR
06-07-2010, 12:47 AM
OK then you have to draw on FBO.

http://www.opengl.org/wiki/Framebuffer_Objects
http://www.gamedev.net/reference/articles/article2331.asp
http://www.songho.ca/opengl/gl_fbo.html

Render DrawX on the offscreen FBO, then glCopyTexSubImage2d it to a texture, then draw a large textured quad on the visible framebuffer (or for GDI route, draw it with GDI commands).

That way, the FBO is never swapped, and incrementally drawn.