public bool SelectPixelFormat(IntPtr hdc, int colorDepth, int multisample)
{
Gdi.PIXELFORMATDESCRIPTOR pfd = new Gdi.PIXELFORMATDESCRIPTOR();
pfd.nSize = (short)Marshal.SizeOf(pfd);
pfd.nVersion = 1;
pfd.dwFlags = Gdi.PFD_DRAW_TO_WINDOW | Gdi.PFD_SUPPORT_OPENGL | Gdi.PFD_DOUBLEBUFFER;
pfd.iPixelType = (byte)Gdi.PFD_TYPE_RGBA;
pfd.cColorBits = (byte)((colorDepth > 16) ? 24 : colorDepth);
pfd.cAlphaBits = (byte)((colorDepth > 16) ? 8 : 0);
pfd.cDepthBits = 24;
pfd.cStencilBits = 8;
int[] format = new int[1];
if (multisample != 0)
{
// only available with driver support
if (!_hasMultisample || !_hasPixelFormatARB)
return false;
int[] iattr = {
Wgl.WGL_DRAW_TO_WINDOW_ARB, 1,
Wgl.WGL_SUPPORT_OPENGL_ARB, 1,
Wgl.WGL_DOUBLE_BUFFER_ARB, 1,
Wgl.WGL_SAMPLE_BUFFERS_ARB, 1,
Wgl.WGL_ACCELERATION_ARB, Wgl.WGL_FULL_ACCELERATION_ARB,
Wgl.WGL_COLOR_BITS_ARB, pfd.cColorBits,
Wgl.WGL_ALPHA_BITS_ARB, pfd.cAlphaBits,
Wgl.WGL_DEPTH_BITS_ARB, pfd.cDepthBits,
Wgl.WGL_STENCIL_BITS_ARB, pfd.cStencilBits,
Wgl.WGL_SAMPLES_ARB, multisample,
0
};
int[] nformats = new int[1];
//int nformats;
Debug.Assert(_wglChoosePixelFormatARB != null, "failed to get proc address for ChoosePixelFormatARB");
// ChoosePixelFormatARB proc address was obtained when setting up a dummy GL context in initialiseWGL()
// since glew hasn't been initialized yet, we have to cheat and use the previously obtained address
bool result = Wgl.wglChoosePixelFormatARB(hdc, iattr, null, 1, format, nformats); // Tao 2.0
//int result = Wgl.wglChoosePixelFormatARB( _wglChoosePixelFormatARB, hdc, iattr, null, 1, format, out nformats );
if (!result || nformats[0] <= 0) // Tao 2.0
//if ( result == 0 || nformats <= 0 )
return false;
}
else
{
format[0] = Gdi.ChoosePixelFormat(hdc, ref pfd);
}
return (format[0] != 0 && Gdi.SetPixelFormat(hdc, format[0], ref pfd));
}