Ejemplo n.º 1
0
        protected override void dispose(bool disposeManagedResources)
        {
            if (!IsDisposed)
            {
                if (disposeManagedResources)
                {
                    if (this.glContext != null)                       // Do We Not Have A Rendering Context?
                    {
                        this.glContext.SetCurrent();
                        this.glContext.Dispose();
                        this.glContext = null;
                    }

                    if (this._window != null)
                    {
                        if (this.fullScreen)
                        {
                            this.displayDevice.RestoreResolution();
                        }

                        this._window.Close();
                        this._window = null;
                    }
                }

                // There are no unmanaged resources to release, but
                // if we add them, they need to be released here.
            }
            // If it is available, make the call to the
            // base class's Dispose(Boolean) method
            base.dispose(disposeManagedResources);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///		Creates &amp; displays the new window.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="width">The width of the window in pixels.</param>
        /// <param name="height">The height of the window in pixels.</param>
        /// <param name="fullScreen">If true, the window fills the screen, with no title bar or border.</param>
        /// <param name="miscParams">A variable number of platform-specific arguments.
        /// The actual requirements must be defined by the implementing subclasses.</param>
        public override void Create(string name, int width, int height, bool fullScreen, NamedParameterList miscParams)
        {
            string title            = name;
            bool   vsync            = false;
            int    depthBuffer      = GraphicsMode.Default.Depth;
            float  displayFrequency = 60f;
            string border           = "resizable";

            this.name          = name;
            this.width         = width;
            this.height        = height;
            colorDepth         = 32;
            this.fullScreen    = fullScreen;
            this.displayDevice = DisplayDevice.Default;

            #region Parameter Handling

            if (miscParams != null)
            {
                foreach (var entry in miscParams)
                {
                    switch (entry.Key)
                    {
                    case "title":
                        title = entry.Value.ToString();
                        break;

                    case "left":
                        left = Int32.Parse(entry.Value.ToString());
                        break;

                    case "top":
                        top = Int32.Parse(entry.Value.ToString());
                        break;

                    case "fsaa":
                        fsaa = Int32.Parse(entry.Value.ToString());
                        break;

                    case "colourDepth":
                    case "colorDepth":
                        colorDepth = Int32.Parse(entry.Value.ToString());
                        break;

                    case "vsync":
                        vsync = entry.Value.ToString() == "No" ? false : true;
                        break;

                    case "displayFrequency":
                        displayFrequency = Int32.Parse(entry.Value.ToString());
                        break;

                    case "depthBuffer":
                        depthBuffer = Int32.Parse(entry.Value.ToString());
                        break;

                    case "border":
                        border = entry.Value.ToString().ToLower();
                        break;

                    case "externalWindowInfo":
                        this.glContext = new OpenTKGLContext((OpenTK.Platform.IWindowInfo)entry.Value);
                        break;

                    case "externalWindowHandle":
                        object handle = entry.Value;
                        IntPtr ptr    = IntPtr.Zero;
                        if (handle.GetType() == typeof(IntPtr))
                        {
                            ptr = (IntPtr)handle;
                        }
                        else if (handle.GetType() == typeof(System.Int32))
                        {
                            ptr = new IntPtr((int)handle);
                        }
                        //glContext = new OpenTKGLContext(Control.FromHandle(ptr), Control.FromHandle(ptr).Parent);

                        WindowEventMonitor.Instance.RegisterWindow(this);
                        fullScreen = false;
                        IsActive   = true;
                        break;

                    case "externalWindow":
                        //glContext = new OpenTKGLContext((Control)entry.Value, ((Control)entry.Value).Parent);
                        WindowEventMonitor.Instance.RegisterWindow(this);
                        fullScreen = false;
                        IsActive   = true;
                        break;

                    default:
                        break;
                    }
                }
            }

            #endregion Parameter Handling

            if (this.glContext == null)
            {
                // create window
                var graphicsMode = new GraphicsMode(new ColorFormat(this.ColorDepth), depthBuffer, this.ColorDepth - depthBuffer > 0 ? this.ColorDepth - depthBuffer : 0, FSAA);
                this._window   = new NativeWindow(width, height, title, GameWindowFlags.Default, graphicsMode, this.displayDevice);
                this.glContext = new OpenTKGLContext(this._window.WindowInfo);

                FileSystem.FileInfoList ico = ResourceGroupManager.Instance.FindResourceFileInfo(ResourceGroupManager.DefaultResourceGroupName, "AxiomIcon.ico");
                if (ico.Count != 0)
                {
                    this._window.Icon = System.Drawing.Icon.ExtractAssociatedIcon(ico[0].Filename);
                }

                if (fullScreen)
                {
                    this.displayDevice.ChangeResolution(width, height, ColorDepth, displayFrequency);
                    this._window.WindowState = WindowState.Fullscreen;
                    IsFullScreen             = true;
                }
                else
                {
                    this._window.WindowState = WindowState.Normal;

                    if (border == "fixed")
                    {
                        this._window.WindowBorder = WindowBorder.Fixed;
                    }
                    else if (border == "resizable")
                    {
                        this._window.WindowBorder = WindowBorder.Resizable;
                    }
                    else if (border == "none")
                    {
                        this._window.WindowBorder = WindowBorder.Hidden;
                    }
                }

                this._window.Title = title;

                WindowEventMonitor.Instance.RegisterWindow(this);

                // lets get active!
                IsActive             = true;
                this.glContext.VSync = vsync;
                this._window.Visible = true;
            }
        }
Ejemplo n.º 3
0
		/// <summary>
		///		Creates &amp; displays the new window.
		/// </summary>
		/// <param name="name"></param>
		/// <param name="width">The width of the window in pixels.</param>
		/// <param name="height">The height of the window in pixels.</param>
		/// <param name="fullScreen">If true, the window fills the screen, with no title bar or border.</param>
		/// <param name="miscParams">A variable number of platform-specific arguments.
		/// The actual requirements must be defined by the implementing subclasses.</param>
		public override void Create( string name, int width, int height, bool fullScreen, NamedParameterList miscParams )
		{
			string title = name;
			bool vsync = false;
			int depthBuffer = GraphicsMode.Default.Depth;
			float displayFrequency = 60f;
			string border = "resizable";

			this.name = name;
			this.width = width;
			this.height = height;
			this.colorDepth = 32;
			this.fullScreen = fullScreen;
			displayDevice = DisplayDevice.Default;

			#region Parameter Handling

			if ( miscParams != null )
			{
				foreach ( KeyValuePair<string, object> entry in miscParams )
				{
					switch ( entry.Key )
					{
						case "title":
							title = entry.Value.ToString();
							break;
						case "left":
							left = Int32.Parse( entry.Value.ToString() );
							break;
						case "top":
							top = Int32.Parse( entry.Value.ToString() );
							break;
						case "fsaa":
							fsaa = Int32.Parse( entry.Value.ToString() );
							break;
						case "colourDepth":
						case "colorDepth":
							colorDepth = Int32.Parse( entry.Value.ToString() );
							break;
						case "vsync":
							vsync = entry.Value.ToString() == "No" ? false : true;
							break;
						case "displayFrequency":
							displayFrequency = Int32.Parse( entry.Value.ToString() );
							break;
						case "depthBuffer":
							depthBuffer = Int32.Parse( entry.Value.ToString() );
							break;
						case "border":
							border = entry.Value.ToString().ToLower();
							break;

						case "externalWindowInfo":
							glContext = new OpenTKGLContext( (OpenTK.Platform.IWindowInfo)entry.Value );
							break;

						case "externalWindowHandle":
							object handle = entry.Value;
							IntPtr ptr = IntPtr.Zero;
							if ( handle.GetType() == typeof( IntPtr ) )
							{
								ptr = (IntPtr)handle;
							}
							else if ( handle.GetType() == typeof( System.Int32 ) )
							{
								ptr = new IntPtr( (int)handle );
							}
							//glContext = new OpenTKGLContext(Control.FromHandle(ptr), Control.FromHandle(ptr).Parent);

							WindowEventMonitor.Instance.RegisterWindow( this );
							fullScreen = false;
							IsActive = true;
							break;

						case "externalWindow":
							//glContext = new OpenTKGLContext((Control)entry.Value, ((Control)entry.Value).Parent);
							WindowEventMonitor.Instance.RegisterWindow( this );
							fullScreen = false;
							IsActive = true;
							break;

						default:
							break;
					}
				}
			}

			#endregion Parameter Handling

			if ( glContext == null )
			{
				// create window
				_window = new NativeWindow( width, height, title, GameWindowFlags.Default, new GraphicsMode( GraphicsMode.Default.ColorFormat, depthBuffer, GraphicsMode.Default.Stencil, FSAA ), displayDevice );
				glContext = new OpenTKGLContext( _window.WindowInfo );

				FileSystem.FileInfoList ico = ResourceGroupManager.Instance.FindResourceFileInfo( ResourceGroupManager.DefaultResourceGroupName, "AxiomIcon.ico" );
				if ( ico.Count != 0 )
				{
					_window.Icon = System.Drawing.Icon.ExtractAssociatedIcon( ico[ 0 ].Filename );
				}

				if ( fullScreen )
				{
					displayDevice.ChangeResolution( width, height, ColorDepth, displayFrequency );
					_window.WindowState = WindowState.Fullscreen;
					IsFullScreen = true;
				}
				else
				{
					_window.WindowState = WindowState.Normal;

					if ( border == "fixed" )
						_window.WindowBorder = WindowBorder.Fixed;
					else if ( border == "resizable" )
						_window.WindowBorder = WindowBorder.Resizable;
					else if ( border == "none" )
						_window.WindowBorder = WindowBorder.Hidden;
				}

				_window.Title = title;

				WindowEventMonitor.Instance.RegisterWindow( this );

				// lets get active!
				IsActive = true;
				glContext.VSync = vsync;
				_window.Visible = true;
			}
		}
Ejemplo n.º 4
0
		protected override void dispose( bool disposeManagedResources )
		{
			if ( !IsDisposed )
			{
				if ( disposeManagedResources )
				{
					if ( glContext != null ) // Do We Not Have A Rendering Context?
					{
						glContext.SetCurrent();
						glContext.Dispose();
						glContext = null;
					}

					if ( _window != null )
					{
						if ( fullScreen )
							displayDevice.RestoreResolution();

						_window.Close();
						_window = null;
					}
				}

				// There are no unmanaged resources to release, but
				// if we add them, they need to be released here.
			}
			// If it is available, make the call to the
			// base class's Dispose(Boolean) method
			base.dispose( disposeManagedResources );
		}