   OpenGL and MFC DCs?
  What is the preferred way of handling OpenGL DCs with MFC?I've seen two ways.  One way, the DC is simply retrieved from the window, and then released: CDC* pDC = GetDC(); // do something with pDC ReleaseDC(pDC);Another way, I've seen the DC is allocated once and kept around until it's no longer needed: m_pDC = new CClientDC(this); // keep itThis DC never needs to be released.Is there anything wrong/bad about method #2?[Edited by - samster581 on June 9, 2010 5:31:44 PM]
  It is just fine to use the second method, but without "new" operator. Like this:   CClientDC dc(pWnd);After exiting the scope the object will be destroyed and in its destructor will call ReleaseDC. In the code you have posted, the programmer used name m_pDC, which suggests that it is a member-variable (attribute) of the class. Take a look at the destructor and you'll probably find the destruction code.   ;  That would be the same as method #1 using a cloned DC.  Method #2 is about storing a persistent global DC, that's used for all functions, and not temporarily allocating it for a local function call.I'm just interested if there's any limitations allocating a private DC for global use, rather than using the window's DC for local use.   ;  I don't see any reason to have a "global" DC. Furthermore, if you have a single thread that draws into a single window (and without interfering with GDI or similar drawing), then probably you don't even need to call MakeCurrent() all the time. I prefer to grab DC just before an OpenGL call and thread-safely bind it to the GL context.   bool GLRenderer::ActivateGL(CDC* pDC)   {m_csGL.Lock();return (bool)wglMakeCurrent(pDC->m_hDC, m_hrc);   };  I'm rendering to multiple GL viewports and using multiple threads.   