Game Development Reference
In-Depth Information
5.
Alternatively, fall back to the pixel format selection function provided by WinAPI:
if ( !PixelFormat )
{
PixelFormat = ::ChoosePixelFormat(DeviceContext, &PFD);
}
return ::SetPixelFormat( DeviceContext,
PixelFormat, &PFD );
}
How it works…
The Reload() function loads opengl32.dll and gets pointers to certain WGL
( http://en.wikipedia.org/wiki/WGL_(API) ) functions:
void LGL::clGLExtRetriever::Reload( sLGLAPI* LGL3 )
{
if ( !FLibHandle ) FLibHandle =
(void*)::LoadLibrary( "opengl32.dll" );
LGL3->lglGetProcAddress = ( PFNwglGetProcAddress )
::GetProcAddress( (HMODULE)FLibHandle, "wglGetProcAddress" );
LGL3->lglCreateContext = ( PFNwglCreateContext )
::GetProcAddress( (HMODULE)FLibHandle, "wglCreateContext" );
LGL3->lglGetCurrentContext = ( PFNwglGetCurrentContext )
::GetProcAddress( (HMODULE)FLibHandle,"wglGetCurrentContext");
LGL3->lglMakeCurrent = ( PFNwglMakeCurrent )
::GetProcAddress( (HMODULE)FLibHandle, "wglMakeCurrent" );
LGL3->lglDeleteContext = ( PFNwglDeleteContext )
::GetProcAddress( (HMODULE)FLibHandle, "wglDeleteContext" );
GetAPI( LGL3 );
}
The GetAPI() function is much bigger but still trivial. The following are just a few lines to give
you the idea:
void LGL::clGLExtRetriever::GetAPI( sLGLAPI* API ) const
{
API->glActiveTexture = ( PFNGLACTIVETEXTUREPROC )
GetGLProc( API, "glActiveTexture" );
API->glAttachShader = ( PFNGLATTACHSHADERPROC )
GetGLProc( API, "glAttachShader" );
The complete source code is in the 1_OpenGL3 folder. You can build it with make :
>make all
 
Search WWH ::




Custom Search