title: Using OpenGL Vertex Buffer Objects with Dynamically linked OpenGL from Windows
body: <p>I am working on setting up a basic OpenGL application by dynamically linking the opengl32.dll file pre-packaged with Windows (That part is non-optional). However I am having quite a lot of difficulty getting procedure addresses for the functions related to Vertex Buffer Objects.</p>
  
  <p>My initial investigations have revealed that windows only exposes the OpenGL 1.1 specification at first, and wglGetProcAddress calls need to be used to get any functions more recent than that. So I modified my code to attempt that method as well. I am using glGenBuffers as my example case, and have attempted four different attempts to load it, and all fail. I have also used glGetString to check my version number which is reported as major version 4, so I doubt it lacks VBO support.</p>
  
  <p>How should I be getting the proc addresses for these VBO functions?</p>
  
  <p>A minimized example of the code I'm dealing with is here:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "windows.h"
  
  using namespace std;
  
  int main()
  {
  
  //Load openGL and get necessary functions
  HINSTANCE hDLL = LoadLibrary("opengl32.dll");
  PROC WINAPI(*winglGetProcAddress)(LPCSTR);
  void(*genBuffers)(int, unsigned int*);
  
  if(hDLL)
  {
      winglGetProcAddress = (PROC WINAPI(*)(LPCSTR))GetProcAddress(hDLL, "wglGetProcAddress");
      if(winglGetProcAddress == NULL){cout &lt;&lt; "wglGetProcAddress not found!" &lt;&lt; endl; return 0;}
  
      genBuffers = (void(*)(int, unsigned int*))GetProcAddress(hDLL, "glGenBuffers");
      if(genBuffers == NULL){genBuffers = (void(*)(int, unsigned int*))winglGetProcAddress("glGenBuffers");}
  }
  else
  {cout &lt;&lt; "This application requires Open GL support." &lt;&lt; endl; return 0;}
  
  //glGenBuffers not supported, fallback to glGenBuffersARB
  if(genBuffers == NULL)
  {
      genBuffers = (void(*)(int, unsigned int*))GetProcAddress(hDLL, "glGenBuffersARB");
      if(genBuffers == NULL){genBuffers = (void(*)(int, unsigned int*))winglGetProcAddress("glGenBuffersARB");}
      if(genBuffers == NULL)
      {cout &lt;&lt; "Could not locate glGenBuffers or glGenBuffersARB in opengl32.dll." &lt;&lt; endl; return 0;}
  }
  
  //get a Vertex Buffer Object
  unsigned int a[1];
  genBuffers(1, a);
  
  //cleanup
  if(!FreeLibrary(hDLL))
  {cout &lt;&lt; "Failed to free the opengl32.dll library." &lt;&lt; endl;}
  
  return 0;
  }
  </code></pre>
  
  <p>When run, it loads the library and get's the wglGetProcAddress correctly, but then outputs the "Could not locate glGenBuffers or glGenBuffersARB in opengl32.dll." error, indicating it failed to get either "glGenBuffers" or "glGenBuffersARB" using either "GetProcAddress" or "wglGetProcAddress".</p>
  
  <p>Alternatively, if this does mean I do not have VBO support, will a driver update help, or is it even possible to get it supported? I'd really rather not use deprecated immediate mode calls.</p>
  
  <p>I am running this in Code::Blocks, on Windows XP, Intel Core i5, with an NVIDIA GeForce GTX 460.</p>