public Application(IApplicationLogic logic, ApplicationSettings settings) { m_keys = new bool[0xFF]; m_thread = Thread.CurrentThread; m_actions = new Queue<Action>(); m_logic = logic; m_display = new Display(this, WindowProc, settings.DisplayStyle); GL.Initialize( m_display, settings.DisplayColorBits, settings.DisplayDepthBits, settings.Debug ); GL.SwapInterval(settings.VerticalSynchronization ? 1 : 0); m_synchronizationContext = new ApplicationSynchronizationContext(m_display.Handle); m_stopwatch = new Stopwatch(); }
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)); }