Пример #1
0
        private void ConstructContext()
        {
            OpenTK.Graphics.GraphicsContextFlags flags = OpenTK.Graphics.GraphicsContextFlags.Default;
            int major = 1;
            int minor = 0;

            OpenTK.Platform.IWindowInfo windowInfo = Window.window.WindowInfo;
            if (System.Environment.OSVersion.Platform == PlatformID.Win32NT ||
                System.Environment.OSVersion.Platform == PlatformID.Win32S ||
                System.Environment.OSVersion.Platform == PlatformID.Win32Windows ||
                System.Environment.OSVersion.Platform == PlatformID.WinCE)
            {
                major = 4;
                minor = 4;
            }
            if (this.Context == null || this.Context.IsDisposed)
            {
                OpenTK.Graphics.ColorFormat colorFormat = new OpenTK.Graphics.ColorFormat(8, 8, 8, 8);
                int depth   = 24;//TODO: wth?
                int stencil = 8;
                int samples = 4;

                OpenTK.Graphics.GraphicsMode mode = new OpenTK.Graphics.GraphicsMode(colorFormat, depth, stencil, samples);
                try
                {
                    this.Context = new OpenTK.Graphics.GraphicsContext(mode, windowInfo, major, minor, flags);
                    //this.Context = Window.Context;
                }
                catch (Exception ex)
                {
                    mode         = OpenTK.Graphics.GraphicsMode.Default;
                    major        = 1;
                    minor        = 0;
                    flags        = OpenTK.Graphics.GraphicsContextFlags.Default;
                    this.Context = new OpenTK.Graphics.GraphicsContext(mode, windowInfo, major, minor, flags);
                }
            }

            this.Context.MakeCurrent(windowInfo);
            (this.Context as OpenTK.Graphics.IGraphicsContextInternal).LoadAll();
            ThreadingHelper.Initialize(windowInfo, major, minor, contextFlags);
            this.Context.MakeCurrent(windowInfo);
        }
Пример #2
0
        public Game()
        {
            OpenTK.Graphics.GraphicsContext.ShareContexts = true;
            var window = new GameWindow(1280, 720);

            Window = new Window(window);
            ConstructContext();

            GraphicsDevice          = new GraphicsDevice(this, Context);
            GraphicsDevice.Viewport = new Viewport(window.ClientRectangle);
            window.Context.MakeCurrent(window.WindowInfo);
            window.Context.LoadAll();
            GL.Viewport(window.ClientRectangle);
            //Window.Location = new System.Drawing.Point();
            Mouse = new MouseDevice(window.Mouse);
            engenious.Input.Mouse.UpdateWindow(window);
            window.FocusedChanged += Window_FocusedChanged;
            window.Closing        += delegate(object sender, System.ComponentModel.CancelEventArgs e)
            {
                Exiting?.Invoke(this, new EventArgs());
            };

            gameTime = new GameTime(new TimeSpan(), new TimeSpan());

            window.UpdateFrame += delegate(object sender, FrameEventArgs e)
            {
                Components.Sort();

                gameTime.Update(e.Time);

                Update(gameTime);
            };
            window.RenderFrame += delegate(object sender, FrameEventArgs e)
            {
                ThreadingHelper.RunUIThread();
                GraphicsDevice.Clear(Color.CornflowerBlue);
                Draw(gameTime);

                GraphicsDevice.Present();
            };
            window.Resize += delegate(object sender, EventArgs e)
            {
                GraphicsDevice.Viewport = new Viewport(window.ClientRectangle);
                GL.Viewport(window.ClientRectangle);

                Resized?.Invoke(sender, e);
                OnResize(this, e);
            };
            window.Load += delegate(object sender, EventArgs e)
            {
                Initialize();
                LoadContent();
            };
            window.Closing += delegate(object sender, System.ComponentModel.CancelEventArgs e)
            {
                OnExiting(this, new EventArgs());
            };
            window.KeyPress += delegate(object sender, KeyPressEventArgs e)
            {
                KeyPress?.Invoke(this, e.KeyChar);
            };

            //Window.Context.MakeCurrent(Window.WindowInfo);

            Content    = new engenious.Content.ContentManager(GraphicsDevice);
            Components = new GameComponentCollection();
        }