Beispiel #1
0
        internal static void Initialize(Display display, int colorBits, int depthBits, bool debug)
        {
            m_debug = debug;

            WinApi.PixelFormatDescriptor pixelFormat = new WinApi.PixelFormatDescriptor()
            {
                size      = (ushort)Marshal.SizeOf(typeof(WinApi.PixelFormatDescriptor)),
                version   = 1,
                flags     = WinApi.PFD_DRAW_TO_WINDOW | WinApi.PFD_SUPPORT_OPENGL | WinApi.PFD_DOUBLEBUFFER,
                pixelType = WinApi.PFD_TYPE_RGBA,
                colorBits = (byte)colorBits,
                depthBits = (byte)depthBits
            };

            int pixelFormatIndex = WinApi.ChoosePixelFormat(display.DeviceContext, ref pixelFormat);

            var result = WinApi.SetPixelFormat(display.DeviceContext, pixelFormatIndex, ref pixelFormat);

            var temporaryContext = WinApi.wglCreateContext(display.DeviceContext);

            WinApi.wglMakeCurrent(display.DeviceContext, temporaryContext);

            var wglCreateContextAttribsARB =
                (Delegate_CreateContextAttribsARB)
                Marshal.GetDelegateForFunctionPointer(
                    wglGetProcAddress("wglCreateContextAttribsARB"),
                    typeof(Delegate_CreateContextAttribsARB)
                    );

            var profileBit = CONTEXT_CORE_PROFILE_BIT_ARB;

            if (debug)
            {
                profileBit |= CONTEXT_DEBUG_BIT_ARB;
            }

            m_context = wglCreateContextAttribsARB(
                display.DeviceContext, IntPtr.Zero, new uint[] {
                CONTEXT_MAJOR_VERSION_ARB, 3,
                CONTEXT_MINOR_VERSION_ARB, 0,
                CONTEXT_PROFILE_MASK_ARB, profileBit,
                0
            }
                );

            WinApi.wglDeleteContext(temporaryContext);
            WinApi.wglMakeCurrent(display.DeviceContext, m_context);

            InitializeFunctions();

            Engine.LogInfo("OpenGL version: {0}", Marshal.PtrToStringAnsi(GL.GetString(GL.VERSION)));
            Engine.LogInfo("GLSL version: {0}", Marshal.PtrToStringAnsi(GL.GetString(GL.SHADING_LANGUAGE_VERSION)));
            Engine.LogInfo("Vendor: {0}", Marshal.PtrToStringAnsi(GL.GetString(GL.VENDOR)));
            Engine.LogInfo("Renderer: {0}", Marshal.PtrToStringAnsi(GL.GetString(GL.RENDERER)));

            m_SwapInterval = (Delegate_SwapInterval)GetFunctionDelegate("wglSwapIntervalEXT", typeof(Delegate_SwapInterval));
        }
Beispiel #2
0
        internal static void Initialize(Display display, int colorBits, int depthBits, bool debug)
        {
            m_debug = debug;

            WinApi.PixelFormatDescriptor pixelFormat = new WinApi.PixelFormatDescriptor()
            {
                size = (ushort)Marshal.SizeOf(typeof(WinApi.PixelFormatDescriptor)),
                version = 1,
                flags = WinApi.PFD_DRAW_TO_WINDOW | WinApi.PFD_SUPPORT_OPENGL | WinApi.PFD_DOUBLEBUFFER,
                pixelType = WinApi.PFD_TYPE_RGBA,
                colorBits = (byte)colorBits,
                depthBits = (byte)depthBits
            };

            int pixelFormatIndex = WinApi.ChoosePixelFormat(display.DeviceContext, ref pixelFormat);

            var result = WinApi.SetPixelFormat(display.DeviceContext, pixelFormatIndex, ref pixelFormat);

            var temporaryContext = WinApi.wglCreateContext(display.DeviceContext);
            WinApi.wglMakeCurrent(display.DeviceContext, temporaryContext);

            var wglCreateContextAttribsARB =
                (Delegate_CreateContextAttribsARB)
                Marshal.GetDelegateForFunctionPointer(
                wglGetProcAddress("wglCreateContextAttribsARB"),
                typeof(Delegate_CreateContextAttribsARB)
            );

            var profileBit = CONTEXT_CORE_PROFILE_BIT_ARB;

            if (debug)
            {
                profileBit |= CONTEXT_DEBUG_BIT_ARB;
            }

            m_context = wglCreateContextAttribsARB(
                display.DeviceContext, IntPtr.Zero, new uint[] {
                    CONTEXT_MAJOR_VERSION_ARB, 3,
                    CONTEXT_MINOR_VERSION_ARB, 0,
                    CONTEXT_PROFILE_MASK_ARB, profileBit,
                    0
                }
            );

            WinApi.wglDeleteContext(temporaryContext);
            WinApi.wglMakeCurrent(display.DeviceContext, m_context);

            InitializeFunctions();

            Engine.LogInfo("OpenGL version: {0}", Marshal.PtrToStringAnsi(GL.GetString(GL.VERSION)));
            Engine.LogInfo("GLSL version: {0}", Marshal.PtrToStringAnsi(GL.GetString(GL.SHADING_LANGUAGE_VERSION)));
            Engine.LogInfo("Vendor: {0}", Marshal.PtrToStringAnsi(GL.GetString(GL.VENDOR)));
            Engine.LogInfo("Renderer: {0}", Marshal.PtrToStringAnsi(GL.GetString(GL.RENDERER)));

            m_SwapInterval = (Delegate_SwapInterval)GetFunctionDelegate("wglSwapIntervalEXT", typeof(Delegate_SwapInterval));
        }