title: Removal of OpenGL rubber banding artefacts
body: <p>I'm working with some OpenGL code for scientific visualization and I'm having issues getting its rubber banding working on newer hardware. The code is drawing a "Zoom Window" over an existing scene with one corner of the "Zoom Window" at the stored left-click location, and the other under the mouse as it is moved. On the second left-click the scene zooms into the selected window.</p>
  
  <p>The symptoms I am seeing as the mouse is moved across the scene are:</p>
  
  <ol>
  <li>Rubber banding artefacts appearing which are the lines used to create the "Zoom Window" not being removed from the buffer by the second "RenderLogic" pass (see code below)</li>
  <li>I can clearly see the contents of the previous buffer flashing up and disappearing as the buffers are swapped</li>
  </ol>
  
  <p>The above problem doesn't happen on low end hardware such as the integrated graphics on a netbook I have. Also, I can't recall this problem ~5 years ago when this code was written.</p>
  
  <p>Here are the relevant code sections, trimmed down to focus on the relevant OpenGL:</p>
  
  <pre><code>// Called by every mouse move event
  // Makes use of current device context (m_hDC) and rendering context (m_hRC)
  void MyViewClass::DrawLogic()
  {
      BOOL bSwapRv = FALSE;
  
      // Make the rendering context current
      if (!wglMakeCurrent(m_hDC, m_hRC))
          // ... error handling
  
      // Perform the logic rendering
      glLogicOp(GL_XOR);
      glEnable(GL_COLOR_LOGIC_OP);
      // Draws the rectangle on the buffer using XOR op
      RenderLogic();
      bSwapRv = ::SwapBuffers(m_hDC);
      // Removes the rectangle from the buffer via a second pass
      RenderLogic();
      glDisable(GL_COLOR_LOGIC_OP);
  
      // Release the rendering context
      if (!wglMakeCurrent(NULL, NULL))
          // ... error handling
  }
  
  void MyViewClass::RenderLogic(void)
  {
      glLineWidth(1.0f);
      glColor3f(0.6f,0.6f,0.6f);
      glEnable(GL_LINE_STIPPLE);
      glLineStipple(1, 0x0F0F);
      glBegin(GL_LINE_LOOP);
          // Uses custom "Point" class with Coords() method returning double*
          // Draw rectangle with corners at clicked location and current location
          glVertex2dv(m_pntClickLoc.Coords());
          glVertex2d(m_pntCurrLoc.X(), m_pntClickLoc.Y());
          glVertex2dv(m_pntCurrLoc.Coords());
          glVertex2d(m_pntClickLoc.X(), m_pntCurrLoc.Y());
      glEnd();
      glDisable(GL_LINE_STIPPLE);
  }
  
  // Setup code that might be relevant to the buffer configuration
  bool MyViewClass::SetupPixelFormat()
  {
      PIXELFORMATDESCRIPTOR pfd = {
          sizeof(PIXELFORMATDESCRIPTOR),
          1,                      // Version number (?)
          PFD_DRAW_TO_WINDOW      // Format must support window
          | PFD_SUPPORT_OPENGL    // Format must support OpenGL
          | PFD_DOUBLEBUFFER,     // Must support double buffering
          PFD_TYPE_RGBA,          // Request an RGBA format
          32,                     // Select a 32 bit colour depth
          0, 0, 0, 0, 0, 0,       // Colour bits ignored (?)
          8,                      // Alpha buffer bits
          0,                      // Shift bit ignored (?)
          0,                      // No accumulation buffer
          0, 0, 0, 0,             // Accumulation bits ignored
          16,                     // 16 bit Z-buffer
          0,                      // No stencil buffer
          0,                      // No accumulation buffer (?)
          PFD_MAIN_PLANE,         // Main drawing layer
          0,                      // Number of overlay and underlay planes
          0, 0, 0                 // Layer masks ignored (?)
      };
      PIXELFORMATDESCRIPTOR chosen_pfd;
  
      memset(&amp;chosen_pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
      chosen_pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
  
      // Find the closest match to the pixel format
      m_uPixelFormat = ::ChoosePixelFormat(m_hDC, &amp;pfd);
  
      // Make sure a pixel format could be found
      if (!m_uPixelFormat)
          return false;
      ::DescribePixelFormat(m_hDC, m_uPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &amp;chosen_pfd);
  
      // Set the pixel format for the view
      ::SetPixelFormat(m_hDC, m_uPixelFormat, &amp;chosen_pfd);
  
      return true;
  }
  </code></pre>
  
  <p>Any pointers on how to remove the artefacts will be much appreciated.</p>
  
  <p>@Krom - image below</p>
  
  <p><img src="https://i.stack.imgur.com/Cf1c4.png" alt="Artefacts from Zoom Window"></p>