View Full Version : Drawing GDI object on OpenGL makes them flicker!
12-04-2003, 07:47 PM
I have an OPENGL window and when I draw GDI text and line on top of the window using the CClientDC device context, the text and line flickers alot. I have already tried Double buffering but it didnt help. Is there any way I can draw GDI object on the screen without causing flickering. Can I get access to the OpenGL back buffer?
12-04-2003, 08:02 PM
Following is the code I am using to draw the line:
if( m_curr_pDC == NULL)
m_curr_pDC = new CClientDC(this);
// Variable for the window size
// Get the window size
// Create a back buffer
// Create a bitmap for back buffer
window_size.right, window_size.bottom );
// Select the bitmap in the back buffer
// Copy the screen to the back buffer
back_pDC.BitBlt(0,0, window_size.right, window_size.bottom, m_curr_pDC, 0,0, SRCCOPY);
// Now Draw the line in the back buffer
CPen *old_pen = back_pDC.SelectObject(&pen);
if( flag )
old_op = back_pDC.SetROP2(R2_XORPEN);
back_pDC.PolylineTo((POINT *)(&dw_pts),cnt - 1);
// Copy the back buffer to the screen
m_curr_pDC->BitBlt(0,0, window_size.right, window_size.bottom, &back_pDC, 0,0, SRCCOPY);
// Select the old pen back
if( flag )
// Delete the Back buffer and its BMP
[This message has been edited by flare (edited 12-04-2003).]
12-05-2003, 12:18 AM
First, make sure your WM_ERASEBKGND event handler returns nonzero to keep the defautl window handler from clearing the window, your OpenGL code does that.
GDI doesn't know anything about OpenGL backbuffers, you can get no direct access.
You can get access to the back buffer contents by glReadPixels, but then you have access to the OpenGL anyway and shouldn't use GDI to draw a line, use OpenGL only.
If you want to do that on a window somebody else rendered with OpenGL or with code you have no access to, you cannot fix the flicker. Just draw the GDI line directly into the frontbuffer then, much quicker than your method.
12-05-2003, 01:59 AM
So you mean that if I want to remove the flicker I will have to draw the lines and text in OpenGL. I cannot have any use of SwapBuffers() and the opengl Back buffer?
Actually, all the remaining output is done in OpenGL but the text and lines are drawn in GDI... All the drawing is done before the GDI calls. After the GDI calls I call glDrawBuffer( GL_BACK ) and then glFlush().
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.