/// <summary> /// This function creates OpenGL from a handle to a device context. /// </summary> /// <param name="hDC">The handle to the device context.</param> /// <returns>True if creation was successful.</returns> protected virtual unsafe bool Create(IntPtr hDC) { // Create the big lame pixel format majoo. PIXELFORMATDESC pixelFormat = new PIXELFORMATDESC(); // Set the values for the pixel format. pixelFormat.nSize = 40; pixelFormat.nVersion = 1; pixelFormat.dwFlags = (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER); pixelFormat.iPixelType = PFD_TYPE_RGBA; pixelFormat.cColorBits = 24; pixelFormat.cRedBits = 0; pixelFormat.cRedShift = 0; pixelFormat.cGreenBits = 0; pixelFormat.cGreenShift = 0; pixelFormat.cBlueBits = 0; pixelFormat.cBlueShift = 0; pixelFormat.cAlphaBits = 0; pixelFormat.cAlphaShift = 0; pixelFormat.cAccumBits = 0; pixelFormat.cAccumRedBits = 0; pixelFormat.cAccumGreenBits = 0; pixelFormat.cAccumBlueBits = 0; pixelFormat.cAccumAlphaBits = 0; pixelFormat.cDepthBits = 16; pixelFormat.cStencilBits = 0; pixelFormat.cAuxBuffers = 0; pixelFormat.iLayerType = PFD_MAIN_PLANE; pixelFormat.bReserved = 0; pixelFormat.dwLayerMask = 0; pixelFormat.dwVisibleMask = 0; pixelFormat.dwDamageMask = 0; // Match an appropriate pixel format int iPixelformat = ChoosePixelFormat(hDC, pixelFormat); if (iPixelformat == 0) { return(false); } // Sets the pixel format if (SetPixelFormat(hDC, iPixelformat, pixelFormat) == 0) { return(false); } // Create a new OpenSharpGL rendering contex handleRenderContext = wglCreateContext(hDC); // Make the OpenSharpGL rendering context the current rendering context wglMakeCurrent(hDC, handleRenderContext); return(true); }
/// <summary> /// This function creates OpenGL from a handle to a device context. /// </summary> /// <param name="hDC">The handle to the device context.</param> /// <returns>True if creation was successful.</returns> protected unsafe virtual bool Create(IntPtr hDC) { // Create the big lame pixel format majoo. PIXELFORMATDESC pixelFormat = new PIXELFORMATDESC(); // Set the values for the pixel format. pixelFormat.nSize = 40; pixelFormat.nVersion = 1; pixelFormat.dwFlags = (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER); pixelFormat.iPixelType = PFD_TYPE_RGBA; pixelFormat.cColorBits = 24; pixelFormat.cRedBits = 0; pixelFormat.cRedShift = 0; pixelFormat.cGreenBits = 0; pixelFormat.cGreenShift = 0; pixelFormat.cBlueBits = 0; pixelFormat.cBlueShift = 0; pixelFormat.cAlphaBits = 0; pixelFormat.cAlphaShift = 0; pixelFormat.cAccumBits = 0; pixelFormat.cAccumRedBits = 0; pixelFormat.cAccumGreenBits = 0; pixelFormat.cAccumBlueBits = 0; pixelFormat.cAccumAlphaBits = 0; pixelFormat.cDepthBits = 16; pixelFormat.cStencilBits = 0; pixelFormat.cAuxBuffers = 0; pixelFormat.iLayerType = PFD_MAIN_PLANE; pixelFormat.bReserved = 0; pixelFormat.dwLayerMask = 0; pixelFormat.dwVisibleMask = 0; pixelFormat.dwDamageMask = 0; // Match an appropriate pixel format int iPixelformat = ChoosePixelFormat(hDC, pixelFormat); if(iPixelformat == 0 ) return false; // Sets the pixel format if(SetPixelFormat(hDC, iPixelformat, pixelFormat) == 0) return false; // Create a new OpenSharpGL rendering contex handleRenderContext = wglCreateContext(hDC); // Make the OpenSharpGL rendering context the current rendering context wglMakeCurrent(hDC, handleRenderContext); return true; }
public unsafe static extern int SetPixelFormat(IntPtr hDC, int iPixelFormat, [In, MarshalAs(UnmanagedType.LPStruct)] PIXELFORMATDESC ppfd);