title: Resetting OpenGL extension pointers in Windows API
body: <p>Some time ago I started working on OpenGL(3.3) renderer for MFC program.Everything was fine till I decided to run some OpenGL debugging tools to see if I have some silent errors.I used 
  <a href="http://www.gremedy.com/" rel="nofollow">gDEBugger</a> .Running  gDebug program analyzing  tool I immediately started getting errors of the following type:</p>
  
  <p><strong>Debug String: Detected error: The debugged process asked for an extension function pointer (glGenBuffers) from one render context, but called this function pointer in another render context (context #2)</strong> </p>
  
  <p>In fact every GLEW method gets this error.Now I started looking for a problem in forums and also on MSDN and I found some people mention that in Windows environment some GLEW methods pointers should be redefined.Also I stumbled upon <a href="https://sites.google.com/site/opengltutorialsbyaks/introduction-to-opengl-3-2---tutorial-01" rel="nofollow">this tutorial</a> which shows how pretty every GLEW method is redefined using Windows OpenGL methods like these:</p>
  
  <pre><code>void CGLRenderer::InitAPI()
  {
    // Program
    glCreateProgram = (PFNGLCREATEPROGRAMPROC)wglGetProcAddress("glCreateProgram");
    glDeleteProgram = (PFNGLDELETEPROGRAMPROC)wglGetProcAddress("glDeleteProgram");
    glUseProgram = (PFNGLUSEPROGRAMPROC)wglGetProcAddress("glUseProgram");
    ...
    ....
  </code></pre>
  
  <p>My OpenGL context set-up looks like this:</p>
  
  <pre><code>   bool OpenGLMain::create30Context(HDC device_context){
  //this-&gt;hwnd=hwnd;
  
  
  hdc=device_context;//GetDC(hwnd);
  
  hdcGlobal=&amp;hdc;
  
  
     PIXELFORMATDESCRIPTOR kPFD;
     memset(&amp;kPFD,0,sizeof(PIXELFORMATDESCRIPTOR));
     kPFD.nSize=sizeof(PIXELFORMATDESCRIPTOR);
     kPFD.nVersion=1;
     kPFD.dwFlags=
     PFD_DRAW_TO_WINDOW|
     PFD_SUPPORT_OPENGL|
     PFD_GENERIC_ACCELERATED|
     PFD_DOUBLEBUFFER;
     kPFD.iPixelType=PFD_TYPE_RGBA;
     kPFD.cColorBits=32;
     kPFD.cDepthBits=32;
     kPFD.cStencilBits=8;
     kPFD.iLayerType=PFD_MAIN_PLANE;
  
     int iPixelFormat=ChoosePixelFormat(hdc,&amp;kPFD);
     if(iPixelFormat==0){
   //  ReleaseDC(window,gs_hWindowDC);
     return false;
     }
    BOOL bSuccess=SetPixelFormat(hdc,iPixelFormat,&amp;kPFD);
    if(!bSuccess){
    // ReleaseDC(window,gs_hWindowDC);
     return false;
     }
  
     /////////init opengl context
  
    HGLRC tempOpenGLContext=wglCreateContext(hdc);/////Openggl 2.1
    wglMakeCurrent(hdc,tempOpenGLContext);////male openGL 2.1 context current and active
    GLenum error =glewInit();
  
    if(error!=GLEW_OK){
     return false;
    }
     /////////context setup///////
     int attributes[]={
     WGL_CONTEXT_MAJOR_VERSION_ARB,3,
     WGL_CONTEXT_MINOR_VERSION_ARB,2,
     WGL_CONTEXT_FLAGS_ARB,WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,0
  
  
                      };
  
  
     if(wglewIsSupported("WGL_ARB_create_context")==1){
  
     hrc=wglCreateContextAttribsARB(hdc,NULL,attributes);///create OpenGL 3x context based on the supplied attributes
     wglMakeCurrent(NULL,NULL);//remove temp context
     wglDeleteContext(tempOpenGLContext);
     wglMakeCurrent(hdc,hrc);
  
  
    }else{
     hrc=tempOpenGLContext;////if no support for OGL 3x detected roll back to 2.0
    }
     /////////version check///////////////
     int glVersion[2]={-1,-1};
     glGetIntegerv(GL_MAJOR_VERSION,&amp;glVersion[0]);
     glGetIntegerv(GL_MINOR_VERSION,&amp;glVersion[1]);
  
       std::cout&lt;&lt;"Using openGL"&lt;&lt;glVersion[0]&lt;&lt;"."&lt;&lt;glVersion[1]&lt;&lt;
       std::endl;     
   OutputDebugString(L"Using OPENGL version:"+glVersion[0]);
  
  return true;
    }
  </code></pre>
  
  <p>Now I am really confused at this point because in fact the program runs fine inside VisualStudio without redefining all these GLEW methods.But it shows the empty screen (no geometry) if I run the executable directly.Also in all the other examples and tutorials I have ever read it had never been mentioned that one has to reset pointers on GLEW API methods.So my question is if anybody can point out to the right way to integrate OpenGL 3.3 in Windows API because it seems that there are many ways doing it.  </p>