void IDualityBackend.Init() { // Determine available and default graphics modes this.QueryGraphicsModes(); activeInstance = this; }
public NativeWindow(GraphicsMode mode, WindowOptions options) { if (options.ScreenMode == ScreenMode.Fullscreen || options.ScreenMode == ScreenMode.FullWindow) { if (DisplayDevice.Default != null) { options.Size = new Point2( DisplayDevice.Default.Width, DisplayDevice.Default.Height); } } GameWindowFlags windowFlags = GameWindowFlags.Default; if (options.ScreenMode == ScreenMode.FixedWindow) { windowFlags = GameWindowFlags.FixedWindow; } else if (options.ScreenMode == ScreenMode.Fullscreen) { windowFlags = GameWindowFlags.Fullscreen; } VSyncMode vsyncMode; switch (options.RefreshMode) { default: case RefreshMode.NoSync: case RefreshMode.ManualSync: vsyncMode = VSyncMode.Off; break; case RefreshMode.VSync: vsyncMode = VSyncMode.On; break; case RefreshMode.AdaptiveVSync: vsyncMode = VSyncMode.Adaptive; break; } this.refreshMode = options.RefreshMode; this.internalWindow = new InternalWindow( this, options.Size.X, options.Size.Y, mode, options.Title, windowFlags); this.internalWindow.MakeCurrent(); this.internalWindow.CursorVisible = true; if (!options.SystemCursorVisible) { this.internalWindow.Cursor = MouseCursor.Empty; } this.internalWindow.VSync = vsyncMode; // Log some general info on the graphics context we've set up GraphicsBackend.LogOpenGLContextSpecs(this.internalWindow.Context); // Retrieve icon from executable file and set it as window icon string executablePath = null; try { Assembly entryAssembly = Assembly.GetEntryAssembly(); if (entryAssembly != null) { executablePath = Path.GetFullPath(entryAssembly.Location); if (File.Exists(executablePath)) { this.internalWindow.Icon = Icon.ExtractAssociatedIcon(executablePath); } } } // As described in issue 301 (https://github.com/AdamsLair/duality/issues/301), the // icon extraction can fail with an exception under certain circumstances. Don't fail // just because of an icon. Log the error and continue. catch (Exception e) { Logs.Core.WriteWarning( "There was an exception while trying to extract the " + "window icon from the game's main executable '{0}'. This is " + "uncritical, but still means something went wrong: {1}", executablePath, LogFormat.Exception(e)); } if (options.ScreenMode == ScreenMode.FullWindow) { this.internalWindow.WindowState = WindowState.Fullscreen; } DualityApp.WindowSize = new Point2(this.internalWindow.ClientSize.Width, this.internalWindow.ClientSize.Height); // Register events and input this.HookIntoDuality(); // Let's see what rendering features we have available GraphicsBackend.ActiveInstance.QueryOpenGLCapabilities(); }
public NativeWindow(GraphicsMode mode, WindowOptions options) { if (options.ScreenMode == ScreenMode.Native && DisplayDevice.Default != null) { options.Width = DisplayDevice.Default.Width; options.Height = DisplayDevice.Default.Height; } GameWindowFlags windowFlags = GameWindowFlags.Default; if (options.ScreenMode == ScreenMode.FixedWindow) { windowFlags = GameWindowFlags.FixedWindow; } else if (options.ScreenMode == ScreenMode.Fullscreen || options.ScreenMode == ScreenMode.Native) { windowFlags = GameWindowFlags.Fullscreen; } this.refreshMode = options.RefreshMode; this.internalWindow = new InternalWindow( this, options.Width, options.Height, mode, options.Title, windowFlags); this.internalWindow.MakeCurrent(); this.internalWindow.CursorVisible = true; if (!options.SystemCursorVisible) { this.internalWindow.Cursor = MouseCursor.Empty; } this.internalWindow.VSync = (options.RefreshMode != RefreshMode.VSync) ? VSyncMode.Off : VSyncMode.On; Log.Core.Write( "Window Specification: " + Environment.NewLine + " Buffers: {0}" + Environment.NewLine + " Samples: {1}" + Environment.NewLine + " ColorFormat: {2}" + Environment.NewLine + " AccumFormat: {3}" + Environment.NewLine + " Depth: {4}" + Environment.NewLine + " Stencil: {5}" + Environment.NewLine + " VSync: {6}" + Environment.NewLine + " SwapInterval: {7}", this.internalWindow.Context.GraphicsMode.Buffers, this.internalWindow.Context.GraphicsMode.Samples, this.internalWindow.Context.GraphicsMode.ColorFormat, this.internalWindow.Context.GraphicsMode.AccumulatorFormat, this.internalWindow.Context.GraphicsMode.Depth, this.internalWindow.Context.GraphicsMode.Stencil, this.internalWindow.VSync, this.internalWindow.Context.SwapInterval); // Retrieve icon from executable file and set it as window icon string executablePath = null; try { Assembly entryAssembly = Assembly.GetEntryAssembly(); if (entryAssembly != null) { executablePath = Path.GetFullPath(entryAssembly.Location); if (File.Exists(executablePath)) { this.internalWindow.Icon = Icon.ExtractAssociatedIcon(executablePath); } } } // As described in issue 301 (https://github.com/AdamsLair/duality/issues/301), the // icon extraction can fail with an exception under certain circumstances. Don't fail // just because of an icon. Log the error and continue. catch (Exception e) { Log.Core.WriteError( "There was an exception while trying to extract the " + "window icon from the game's main executable '{0}'. This is " + "uncritical, but still an error: {1}", executablePath, Log.Exception(e)); } if (options.ScreenMode == ScreenMode.FullWindow) { this.internalWindow.WindowState = WindowState.Fullscreen; } DualityApp.TargetResolution = new Vector2(this.internalWindow.ClientSize.Width, this.internalWindow.ClientSize.Height); // Register events and input this.HookIntoDuality(); // Determine OpenGL capabilities and log them GraphicsBackend.LogOpenGLSpecs(); }
public NativeWindow(GraphicsMode mode, WindowOptions options) { if (options.ScreenMode == ScreenMode.Native) { options.Width = DisplayDevice.Default.Width; options.Height = DisplayDevice.Default.Height; } GameWindowFlags windowFlags = GameWindowFlags.Default; if (options.ScreenMode == ScreenMode.FixedWindow) { windowFlags = GameWindowFlags.FixedWindow; } else if (options.ScreenMode == ScreenMode.Fullscreen || options.ScreenMode == ScreenMode.Native) { windowFlags = GameWindowFlags.Fullscreen; } this.refreshMode = options.RefreshMode; this.internalWindow = new InternalWindow( this, options.Width, options.Height, mode, options.Title, windowFlags); this.internalWindow.MakeCurrent(); this.internalWindow.CursorVisible = true; if (!options.SystemCursorVisible) { this.internalWindow.Cursor = MouseCursor.Empty; } this.internalWindow.VSync = (options.RefreshMode != RefreshMode.VSync) ? VSyncMode.Off : VSyncMode.On; Log.Core.Write("Window Specification: {0}Mode: {1}{0}VSync: {2}{0}SwapInterval: {3}{0}", Environment.NewLine, this.internalWindow.Context.GraphicsMode, this.internalWindow.VSync, this.internalWindow.Context.SwapInterval); // Retrieve icon from executable file and set it as window icon Assembly entryAssembly = Assembly.GetEntryAssembly(); if (entryAssembly != null) { string executablePath = Path.GetFullPath(entryAssembly.Location); if (File.Exists(executablePath)) { this.internalWindow.Icon = Icon.ExtractAssociatedIcon(executablePath); } } if (options.ScreenMode == ScreenMode.FullWindow) { this.internalWindow.WindowState = WindowState.Fullscreen; } DualityApp.TargetResolution = new Vector2(this.internalWindow.ClientSize.Width, this.internalWindow.ClientSize.Height); // Register events and input this.HookIntoDuality(); // Determine OpenGL capabilities and log them GraphicsBackend.LogOpenGLSpecs(); }