public OpenGLControl()
        {
            InitializeComponent();

            Renderables = new List<IGLRenderable>();

            Mode = DisplayMode.LevelView;

            Camera = new SFCamera();
            Camera.UpdateCamera += UpdateCamera;
        }
        /// <summary>
        /// Constructs a new GLControl with the specified DisplayMode.
        /// </summary>
        /// <param name="mode"></param>
        public GLControl(DisplayMode mode)
        {
            InitializeComponent();

            this.SetStyle(ControlStyles.Opaque, true);
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            DoubleBuffered = false;

            this.display_mode = mode;

            this.CreateControl();
        }
Exemple #3
0
        private void LoadNavMeshFromFile(string path)
        {
            try
            {

                tiledNavMesh = new NavMeshJsonSerializer().Deserialize(path);
                navMeshQuery = new NavMeshQuery(tiledNavMesh, 2048);
                hasGenerated = true;
                displayMode = DisplayMode.NavMesh;
            }
            catch (Exception e)
            {
                if (!interceptExceptions)
                    throw;
                else
                {
                    hasGenerated = false;
                    tiledNavMesh = null;
                    navMeshQuery = null;
                    Console.WriteLine("Navmesh loading failed with exception:" + Environment.NewLine + e.ToString());
                }
            }
        }
 private void LoadNavMeshFromFile(string path)
 {
     tiledNavMesh = new NavMeshJsonSerializer().Deserialize(path);
     displayMode = DisplayMode.NavMesh;
 }
 /// <summary>
 /// Constructs a new GameWindow, and opens a render window with the specified DisplayMode.
 /// </summary>
 /// <param name="mode">The DisplayMode of the GameWindow.</param>
 public GameWindow(DisplayMode mode) : this(mode, "OpenTK game window") { }
        /// <summary>
        /// Raises the RenderFrame event, and calls the public function.
        /// </summary>
        /// <param name="e"></param>
        private void OnRenderFrameInternal(RenderFrameEventArgs e)
        {
            if (!this.Exists && !this.IsExiting)
            {
                Debug.Print("WARNING: RenderFrame event raised, without a valid render window. This may indicate a programming error. Creating render window.");
                mode = new DisplayMode(640, 480);
                this.CreateWindow(mode);
            }
            if (RenderFrame != null)
                RenderFrame(this, e);

            // Call the user's override.
            OnRenderFrame(e);
        }
 /// <summary>
 /// Creates a render window for the calling GameWindow, with the specified DisplayMode and Title.
 /// </summary>
 /// <param name="mode">The DisplayMode of the render window.</param>
 /// <param name="title">The Title of the render window.</param>
 /// <remarks>
 /// It is an error to call this function when a render window already exists.
 /// <para>Call DestroyWindow to close the render window.</para>
 /// </remarks>
 /// <exception cref="ApplicationException">Occurs when a render window already exists.</exception>
 private void CreateWindow(DisplayMode mode, string title)
 {
     if (!Exists)
     {
         // TODO: This is a hack - reslove in 0.3.15 once and for all!
         // GLContext is created inside the CreateWindow call.
         glWindow.CreateWindow(mode, out glContext);
         this.Title = title;
     }
     else
         throw new InvalidOperationException("A render window already exists for this GameWindow.");
 }
 /// <summary>
 /// Creates a render window for the calling GameWindow.
 /// </summary>
 /// <param name="mode">The DisplayMode of the render window.</param>
 /// <remarks>
 /// It is an error to call this function when a render window already exists.
 /// <para>Call DestroyWindow to close the render window.</para>
 /// </remarks>
 /// <exception cref="ApplicationException">Occurs when a render window already exists.</exception>
 public void CreateWindow(DisplayMode mode)
 {
     if (!Exists)
     {
         try
         {
             glWindow.CreateWindow(mode, out glContext);
         }
         catch (ApplicationException expt)
         {
             Debug.Print(expt.ToString());
             throw;
         }
     }
     else
     {
         throw new ApplicationException("A render window already exists for this GameWindow.");
     }
 }
        /// <summary>
        /// Constructs a new GameWindow with the specified title, and opens a render window with the
        /// specified DisplayMode.
        /// </summary>
        /// <param name="mode">The DisplayMode of the GameWindow.</param>
        /// <param name="title">The Title of the GameWindow.</param>
        public GameWindow(DisplayMode mode, string title)
        {
            switch (Environment.OSVersion.Platform)
            {
                case PlatformID.Win32NT:
                case PlatformID.Win32S:
                case PlatformID.Win32Windows:
                case PlatformID.WinCE:
                    glWindow = new OpenTK.Platform.Windows.WinGLNative();
                    break;

                case PlatformID.Unix:
                case (PlatformID)128:
                    glWindow = new OpenTK.Platform.X11.X11GLNative();
                    break;

                default:
                    throw new PlatformNotSupportedException(
                        "Your platform is not supported currently. Please, refer to http://opentk.sourceforge.net for more information.");
            }

            glWindow.Destroy += glWindow_Destroy;

            CreateWindow(mode, title);

            //this.vsync = VSyncMode.Adaptive;
            this.VSync = VSyncMode.On;
        }
Exemple #10
0
		private void LoadNavMeshFromFile(string path)
		{
			tiledNavMesh = new NavMeshJsonSerializer().Deserialize(path);
			navMeshQuery = new NavMeshQuery(tiledNavMesh, 2048);
			hasGenerated = true;
			displayMode = DisplayMode.NavMesh;
		}
 /// <summary>
 /// Creates a GLContext and attaches it to this GLControl.
 /// </summary>
 public void CreateContext()
 {
     if (display_mode == null)
         display_mode = new DisplayMode();
     WindowInfo info = new WindowInfo(this);
     
     if (!this.DesignMode)
     {
         // Mono's implementation of Windows.Forms on X11 does not allow the context to
         // have a different colordepth from the parent. To combat this, we do not set a
         // specific depth for the DisplayMode - we let the driver select one instead.
         display_mode.Color = new ColorMode(0);
         context = new GLContext(display_mode, info);
         idle = new PlatformIdle(info);
     }
     else
     {
         context = new DummyGLContext(display_mode);
         idle = new DummyPlatformIdle();
     }
 }
		private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
		{
			if (e.ExceptionObject is CtrlCException)
			{
				Terminate();
				return;
			}

			EventHandler h = OnException;
			if (h != null)
			{
				try
				{
					h(sender, new EventArgs());
				}
				catch (Exception ex)
				{
					Debug.WriteLine(ex.Message);
					Debug.WriteLine(ex.StackTrace.ToString());
				}
			}
			else if (!wnd.IsExiting)
			{
				Exception ex = e.ExceptionObject as Exception;

				WriteLine();
				if (ex == null)
					WriteLine(e.ExceptionObject.ToString());
				else
				{
					while (ex != null)
					{
						WriteLine(ex.Message);
						ex = ex.InnerException;
					}
				}

				if (displayMode != DisplayMode.Characters)
				{
					displayMode = DisplayMode.Characters;

					WriteLine("Press ENTER to continue.");
					ReadLine();
				}
			}

			Terminate();
		}
		/// <summary>
		/// Starts the execution of the application.
		/// </summary>
		protected static void Initialize()
		{
			DisplayDevice MainDisplay = DisplayDevice.Default;

			screenWidth = MainDisplay.Width;
			screenHeight = MainDisplay.Height;

			StackTrace StackTrace = new StackTrace();
			StackFrame StackFrame = StackTrace.GetFrame(1);
			Type T = StackFrame.GetMethod().ReflectedType;
			int i;

			foreach (ScreenBorderAttribute Attr in T.GetCustomAttributes(typeof(ScreenBorderAttribute), true))
			{
				leftMargin = Attr.LeftMargin;
				rightMargin = Attr.RightMargin;
				topMargin = Attr.TopMargin;
				bottomMargin = Attr.BottomMargin;
				borderColor = Attr.BorderColor;
			}

			visibleScreenWidth = screenWidth - leftMargin - rightMargin;
			visibleScreenHeight = screenHeight - topMargin - bottomMargin;

			foreach (AspectRatioAttribute Attr in T.GetCustomAttributes(typeof(AspectRatioAttribute), true))
			{
				double DimX = Attr.Width;
				double DimY = Attr.Height;
				double DesiredAspectRatio = DimX / DimY;
				double CurrentAspectRatio = ((double)visibleScreenWidth) / visibleScreenHeight;
				int Diff;

				if (DesiredAspectRatio > CurrentAspectRatio)
				{
					// Wants wider that screen actually is. Shrink height of visible screen.

					// w/h=a, h=w/a

					visibleScreenHeight = (int)(visibleScreenWidth / DesiredAspectRatio + 0.5);

					Diff = screenHeight - visibleScreenHeight;
					topMargin += Diff / 2;
					bottomMargin += Diff - (Diff / 2);
				}
				else if (DesiredAspectRatio < CurrentAspectRatio)
				{
					// Wants less wide that screen actually is. Shrink width of visible screen.

					// w/h=a, w=a*h

					visibleScreenWidth = (int)(DesiredAspectRatio * visibleScreenHeight + 0.5);

					Diff = screenWidth - visibleScreenWidth;
					leftMargin += Diff / 2;
					rightMargin += Diff - (Diff / 2);
				}
			}

			if (borderColor.IsEmpty)
				borderColor = foregroundColor;

			foreach (CharacterSetAttribute Attr in T.GetCustomAttributes(typeof(CharacterSetAttribute), true))
			{
				characterSetSize = Attr.CharacterSetSize;
				fontName = Attr.FontName;
			}

			foreach (CharactersAttribute Attr in T.GetCustomAttributes(typeof(CharactersAttribute), true))
			{
				consoleWidth = Attr.Width;
				consoleHeight = Attr.Height;
				foregroundColor = Attr.ForegroundColor;
				backgroundColor = Attr.BackgroundColor;

				consoleWindowRight = consoleWidth - 1;
				consoleWindowBottom = consoleHeight - 1;
				consoleWindowWidth = consoleWindowRight - consoleWindowLeft + 1;
				consoleWindowHeight = consoleWindowBottom - consoleWindowTop + 1;

				displayMode = DisplayMode.Characters;
			}

			rasterWidth = visibleScreenWidth;
			rasterHeight = visibleScreenHeight;

			foreach (RasterGraphicsAttribute Attr in T.GetCustomAttributes(typeof(RasterGraphicsAttribute), true))
			{
				rasterWidth = rasterObj.rasterWidth = Attr.Width;
				rasterHeight = rasterObj.rasterHeight = Attr.Height;

				rasterClipRight = rasterObj.rasterClipRight = rasterWidth - 1;
				rasterClipBottom = rasterObj.rasterClipBottom = rasterHeight - 1;

				rasterBackgroundColor = Attr.BackgroundColor;

				displayMode = DisplayMode.RasterGraphics;
			}

			rasterStride = rasterObj.rasterStride = rasterWidth * 4;
			rasterSize = rasterWidth * rasterStride;

			byte R = rasterBackgroundColor.R;
			byte G = rasterBackgroundColor.G;
			byte B = rasterBackgroundColor.B;
			byte A = rasterBackgroundColor.A;

			raster = rasterObj.raster = new byte[rasterSize];

			rasterBlocksX = rasterWidth / RasterBlockSize;
			if ((rasterWidth % RasterBlockSize) != 0)
				rasterBlocksX++;

			rasterBlocksY = rasterHeight / RasterBlockSize;
			if ((rasterHeight % RasterBlockSize) != 0)
				rasterBlocksY++;

			rasterObj.rasterBlocksX = rasterBlocksX;
			rasterObj.rasterBlocksY = rasterBlocksY;

			rasterBlocks = rasterObj.rasterBlocks = new bool[rasterBlocksX * rasterBlocksY];

			i = 0;
			while (i < rasterSize)
			{
				raster[i++] = R;
				raster[i++] = G;
				raster[i++] = B;
				raster[i++] = A;
			}

			consoleSize = consoleWidth * consoleHeight;
			consoleSizeMinusOneRow = consoleWidth * (consoleHeight - 1);

			int c = consoleWidth * consoleHeight;
			int j = 32 % characterSetSize;

			screenBuffer = new int[c];
			foregroundColorBuffer = new Color[c];
			backgroundColorBuffer = new Color[c];

			emptyRow = new int[consoleWidth];
			for (i = 0; i < consoleWidth; i++)
				emptyRow[i] = j;

			Clear();

			AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

			renderingThread = new Thread(ExecutionThread);
			renderingThread.Priority = ThreadPriority.AboveNormal;
			renderingThread.Name = "OpenGL rendering thread";
			renderingThread.Start();

			started.WaitOne();

			Console.SetOut(consoleOutput = new ConsoleOutput());
			Console.SetIn(consoleInput = new ConsoleInput());
			Console.TreatControlCAsInput = true;
		}
 public DisplayMode(DisplayMode mode)
     : this(mode.Width, mode.Height, mode.Color, mode.DepthBits, mode.StencilBits, mode.AuxBits, mode.Buffers,
     mode.Fullscreen, mode.Stereo, mode.Vsync, mode.RefreshRate)
 {
 }
Exemple #15
0
        void IPrimarySwapChain.ResetToFullscreen(ref DisplayMode displayMode, ref SwapChainDescription description)
        {
            fullscreenDisplayMode = displayMode;
            implicitSwapChainDesc = description;

            fullscreenState = FullscreenState.Fullscreen;
            DisplayDevice.Default.ChangeResolution(displayMode.Width, displayMode.Height, device.Adapter.GetFormatInfo(displayMode.FormatID).TotalBits, displayMode.RefreshRate.ToSingle());
            WindowState = WindowState.Fullscreen;
            ResetProcedure();
        }
Exemple #16
0
 void IPrimarySwapChain.GetFullscreenDisplayMode(out DisplayMode displayMode)
 {
     displayMode = fullscreenDisplayMode;
 }