Problem with WGL_ARB_buffer_region Can Somebody help?

currently i am using WGL_ARB_buffer_region.
i use this method to do my save/restore,

//my base class

class COpenGL : public CScrollView{
HGLRC m_hRC; //Rendering Context
CDC* m_pDC; //Device Context

HANDLE region;


// i setup my opengl as usual
BOOL COpenGL::InitOpenGL()
//Get a DC for the Client Area
m_pDC = new CClientDC(this);

//Failure to Get DC
if( m_pDC == NULL )
return FALSE;

if( !SetupPixelFormat() )
return FALSE;

//Create Rendering Context
m_hRC = ::wglCreateContext( m_pDC->GetSafeHdc() );

//Failure to Create Rendering Context
if( m_hRC == 0 )
return FALSE;

//Make the RC Current
if( ::wglMakeCurrent( m_pDC->GetSafeHdc(), m_hRC ) == FALSE )
return FALSE;


region=wglCreateBufferRegionARB(m_pDC->GetSafeHdc(),0,WGL_BACK_COLOR_BUFFER_BIT_ARB | WGL_DEPTH_BUFFER_BIT_ARB);

return TRUE;
// CSbomView is my View class
// CSbomDoc is my Doc class

class CSbomView : public COpenGL{


void CSbomView::SaveCurrentView()
CRect rect;
region=wglCreateBufferRegionARB(m_pDC->GetSafeHdc(),0,WGL_BACK_COLOR_BUFFER_BIT_ARB | WGL_DEPTH_BUFFER_BIT_ARB);
void CSbomView::RestoreCurrentView()
int port[4];
after this i use my SaveCurrentView(), and RestoreCurrentView() to do my save/restore job. It works fine at first( the first child windows never show any problem), but after i close a child window and open a new child window (repeat it a few time 7 to 10 times) my program exit with error automatically. I really dont have any idea with it. Can someone please tell me how to solve the problem Thanks.


  1. Is it we need to create a buffer region once with wglCreateBufferRegionARB untill we close the program or have to recreate a new one every time we want to save a new buffer region?
  2. When will we use wglDeleteBufferRegionARB to delete buffer region, is it when we close our child view(program) or before we want to create a new buffer region?
  3. Can some one tell me the proper way to use WGL_ARB_buffer_region?

See the extension specs

But, it appears that

  1. yes, create once (multiple buffers allowed)
  2. yes, delete at close or when no longer needed
  3. use save and restore functions and check for errors returned by functions. TRUE is successful, FALSE is error, or NULL is error for create can be checked by GetLastError.

i am using MFC, can you tell me and show me only a part of code in which function i should create it and in which function i should delete it. Please help,

void CSbomView::SaveCurrentView()
    CRect rect; 
    //region=wglCreateBufferRegionARB(m_pDC->GetSafeHdc(),0,WGL_BACK_COLOR_BUFFER_BIT_ARB | WGL_DEPTH_BUFFER_BIT_ARB);

From here where the comments have been put in. Delete it before the window closes - destructor could be good.
  1. i am using MDI, so in which function i should create the region? And in which class, the base class or the CSbomView class?
    2)i have tried this method, but still cant save the region. The wglSaveBufferRegionARB return a true value but when i restore it with wglRestoreBufferRegionARB it cant restore the region.
  2. Did you means i should delete the region at CSbomView::~CSbomView() destructor function. i delete the region at the OnDestroy function before i delete m_pDC, cause from the documentation it says that the m_pDC who create the region must be valid when you want to delete the region.


[This message has been edited by chengseesin (edited 05-13-2003).]