How to get OpenGL function pointer for different platforms.

Windows

You can do it using PROC WINAPI wglGetProcAddress( LPCSTR lpszProc); The name of the OpenGL  1.1 (and better) or windows specific WGL function  you want retrieve pointer should be passed as parameter. Note, the name is case-sensitive.   This function only works in the presence of a valid OpenGL context. Indeed, the function pointers it returns are themselves context-specific.  

Linux

Use void* glXGetProcAddress(const GLubyte* procName) function  or  void* glXGetProcAddressARB(const GLubyte* procName) to get leagacy ARB extentions.  Same as in Windows case you need pass exactly matching  function name as parameter.  Linux specific GLX names can be passed as well.

...

OSX

Use void * aglGetProcAddress (char * pszProc);  This one works same same way as wglGetProcAddress() and  glXGetProcAddress();

 Basically you can define macro and use it for any of these platforms:

#if defined WIN32
#  define getGlFncPtr(name) wglGetProcAddress((LPCSTR)name)
#elif defined OSMac_
#  define getGlFncPtr(name) aglGetProcAddress(name)
#elif defined LINUX
#  ifdef GLX_GLXEXT_LEGACY
#     define getGlFncPtr(name) (*glXGetProcAddressARB)((const GLubyte*)name)
#  else
#     define getGlFncPtr(name) (*glXGetProcAddress)((const GLubyte*)name)
#  endif
#endif

No feedback yet

This post has 208 feedbacks awaiting moderation...

Leave a comment

Your email address will not be revealed on this site.
  
(For my next comment on this site)
(Allow users to contact me through a message form -- Your email will not be revealed!)
Trackback address for this post

http://blog.3dgears.com/htsrv/trackback.php?tb_id=41