Undesired clearing of the front buffer

How can I avoid the problem shown here , caused when another window is dragged over the glviewport, or when the viewport is dragged outside the bounds of the desktop, then back in again?

Thanks.

The parts of the buffer that are erased will always be erased (or almost always - essentially the GL specification states that these regions are undefined). If they remain erased when you stop dragging over the region then you are probably drawing to your buffers at an incorrect time (WM_PAINT?).

You need to identify when an area of your window has been erased and redraw it. The easiest way to do this is to draw in a message loop which is in the Nehe base code. It’s something like this…

	while(!done)
	{
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{
			if (msg.message==WM_QUIT)
			{
				done=TRUE;
			}
			else
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
		}
		else
		{
			if (active)
			{
				if (keys[VK_ESCAPE])
				{
					done=TRUE;
				}
				else
				{
					DrawGLScene();
					SwapBuffers(hDC);
				}
			}
		}
	}

So you are saying that any time I drag a window over one of my viewports, I need to detect it and re-render the whole scene?

Okay, will continue there.