MakeCurrent() public method

Makes the GraphicsContext current on the calling thread.
public MakeCurrent ( ) : void
return void
Ejemplo n.º 1
0
        private void OnRenderFrame(object sender, FrameEventArgs e)
        {
            if (GraphicsContext.CurrentContext == null || GraphicsContext.CurrentContext.IsDisposed)
            {
                return;
            }

            //Should not happen at all..
            if (!GraphicsContext.CurrentContext.IsCurrent)
            {
                window.MakeCurrent();
            }

            UpdateWindowState();
        }
Ejemplo n.º 2
0
        private void OnRenderFrame(object sender, FrameEventArgs e)
        {
            if (GraphicsContext.CurrentContext == null || GraphicsContext.CurrentContext.IsDisposed)
            {
                return;
            }

            //Should not happen at all..
            if (!GraphicsContext.CurrentContext.IsCurrent)
            {
                window.MakeCurrent();
            }

            // we should wait until window's not fullscreen to resize
            if (updateClientBounds && window.WindowState == WindowState.Normal)
            {
                // it seems, at least on linux, we can't resize if we disallow user resizing
                // make next state the current state
                _transitiveAllowUserResizing = AllowUserResizing;
                // allow resize to resize window
                window.WindowBorder = WindowBorder.Resizable;

                window.ClientRectangle = new System.Drawing.Rectangle(clientBounds.X,
                                                                      clientBounds.Y, clientBounds.Width, clientBounds.Height);

                updateClientBounds = false;
            }
            else if (_transitiveAllowUserResizing != _allowUserResizing)
            {
                // reset previous value
                AllowUserResizing = _transitiveAllowUserResizing;
            }

            if (window.WindowState != windowState)
            {
                window.WindowState = windowState;
            }

            if (Game != null)
            {
                _drawGameTime.Update(_now - _lastUpdate);
                _lastUpdate = _now;
                Game.DoDraw(_drawGameTime);
            }

            window.SwapBuffers();
        }
Ejemplo n.º 3
0
        private void OnRenderFrame(object sender, FrameEventArgs e)
        {
            if (GraphicsContext.CurrentContext == null || GraphicsContext.CurrentContext.IsDisposed)
            {
                return;
            }

            //Should not happen at all..
            if (!GraphicsContext.CurrentContext.IsCurrent)
            {
                OpenTkGameWindow.MakeCurrent();
            }

            if (Game != null)
            {
                _drawGameTime.Update(_now - _lastUpdate);
                _lastUpdate = _now;
                Game.DoDraw(_drawGameTime);
            }

            OpenTkGameWindow.SwapBuffers();
        }
Ejemplo n.º 4
0
    public void Init(GameWindow gamewindow)
    {
        renderer = new Gwen.Renderer.OpenTK();
        skin = new Gwen.Skin.TexturedBase (renderer, "DefaultSkin.png");
        canvas = new Gwen.Control.Canvas (skin);
        canvas.SetSize (gamewindow.Width, gamewindow.Height);
        canvas.ShouldDrawBackground = true;
        canvas.BackgroundColor = System.Drawing.Color.FromArgb (255, 225, 225, 225);

        input = new Gwen.Input.OpenTK (gamewindow);
        input.Initialize (canvas);

        gamewindow.Keyboard.KeyDown += (s, e) =>
        {
            input.ProcessKeyDown (e);
        };
        gamewindow.Keyboard.KeyUp += (s, e) =>
        {
            input.ProcessKeyUp (e);
        };

        gamewindow.Mouse.ButtonDown += (s, e) =>
        {
            input.ProcessMouseMessage (e);
        };
        gamewindow.Mouse.ButtonUp += (s, e) =>
        {
            input.ProcessMouseMessage (e);
        };
        gamewindow.Mouse.Move += (s, e) =>
        {
            input.ProcessMouseMessage (e);
        };
        gamewindow.Mouse.WheelChanged += (s, e) =>
        {
            input.ProcessMouseMessage (e);
        };

        gamewindow.Load += (s, e) =>
        {
            PreLoad();

            gamewindow.VSync = VSyncMode.On;

            PostLoad();
        };

        gamewindow.Resize += (s, e) =>
        {
            GL.Viewport (0, 0, gamewindow.Width, gamewindow.Height);
            GL.MatrixMode (MatrixMode.Projection);
            GL.LoadIdentity();
            GL.Ortho (0, gamewindow.Width, gamewindow.Height, 0, -1, 1);

            canvas.SetSize (gamewindow.Width, gamewindow.Height);
        };

        gamewindow.UpdateFrame += (s, e) =>
        {
            PreUpdate();

            if (renderer.TextCacheSize > 1000)
                renderer.FlushTextCache();

            PostUpdate();
        };

        gamewindow.RenderFrame += (s, e) =>
        {
            gamewindow.MakeCurrent();

            PreRender();

            canvas.RenderCanvas();

            PostRender();

            gamewindow.SwapBuffers();
        };
    }
Ejemplo n.º 5
0
        private void Initialize()
        {
            GraphicsContext.ShareContexts = true;

            window                   = new OpenTK.GameWindow();
            window.RenderFrame      += OnRenderFrame;
            window.UpdateFrame      += OnUpdateFrame;
            window.Closing          += new EventHandler <CancelEventArgs>(OpenTkGameWindow_Closing);
            window.Resize           += OnResize;
            window.Keyboard.KeyDown += new EventHandler <OpenTK.Input.KeyboardKeyEventArgs>(Keyboard_KeyDown);
            window.Keyboard.KeyUp   += new EventHandler <OpenTK.Input.KeyboardKeyEventArgs>(Keyboard_KeyUp);
#if LINUX
            window.WindowBorder = WindowBorder.Resizable;
#endif
#if WINDOWS
            window.MouseEnter += OnMouseEnter;
            window.MouseLeave += OnMouseLeave;
#endif

            window.KeyPress += OnKeyPress;

            // Set the window icon.
            var assembly = Assembly.GetEntryAssembly();
            if (assembly != null)
            {
                window.Icon = Icon.ExtractAssociatedIcon(assembly.Location);
            }

            updateClientBounds = false;
            clientBounds       = new Rectangle(window.ClientRectangle.X, window.ClientRectangle.Y,
                                               window.ClientRectangle.Width, window.ClientRectangle.Height);
            windowState = window.WindowState;

#if WINDOWS
            {
                var windowInfoType = window.WindowInfo.GetType();
                var propertyInfo   = windowInfoType.GetProperty("WindowHandle");
                _windowHandle = (IntPtr)propertyInfo.GetValue(window.WindowInfo, null);
            }
#endif
            // Provide the graphics context for background loading
            Threading.BackgroundContext = new GraphicsContext(GraphicsMode.Default, window.WindowInfo);
            Threading.WindowInfo        = window.WindowInfo;

            keys = new List <Keys>();

            // Make the foreground context the current context
            if (GraphicsContext.CurrentContext == null || !GraphicsContext.CurrentContext.IsCurrent)
            {
                window.MakeCurrent();
            }

            // mouse
            // TODO review this when opentk 1.1 is released
#if WINDOWS || LINUX
            Mouse.setWindows(window);
#else
            Mouse.UpdateMouseInfo(window.Mouse);
#endif

            //Default no resizing
            AllowUserResizing = false;
        }
Ejemplo n.º 6
0
        private void Initialize()
        {
            GraphicsContext.ShareContexts = true;

            window = new OpenTK.GameWindow();
            window.RenderFrame += OnRenderFrame;
            window.UpdateFrame += OnUpdateFrame;
            window.Closing += new EventHandler<CancelEventArgs>(OpenTkGameWindow_Closing);
            window.Resize += OnResize;
            window.Keyboard.KeyDown += new EventHandler<OpenTK.Input.KeyboardKeyEventArgs>(Keyboard_KeyDown);
            window.Keyboard.KeyUp += new EventHandler<OpenTK.Input.KeyboardKeyEventArgs>(Keyboard_KeyUp);
#if LINUX
            window.WindowBorder = WindowBorder.Resizable;
#endif
#if WINDOWS
            window.MouseEnter += OnMouseEnter;
            window.MouseLeave += OnMouseLeave;
#endif

            window.KeyPress += OnKeyPress;

            // Set the window icon.
            window.Icon = Icon.ExtractAssociatedIcon(Assembly.GetEntryAssembly().Location);

            updateClientBounds = false;
            clientBounds = new Rectangle(window.ClientRectangle.X, window.ClientRectangle.Y,
                                         window.ClientRectangle.Width, window.ClientRectangle.Height);
            windowState = window.WindowState;

#if WINDOWS
            {
                var windowInfoType = window.WindowInfo.GetType();
                var propertyInfo = windowInfoType.GetProperty("WindowHandle");
                _windowHandle = (IntPtr)propertyInfo.GetValue(window.WindowInfo, null);
            }
#endif
            // Provide the graphics context for background loading
            Threading.BackgroundContext = new GraphicsContext(GraphicsMode.Default, window.WindowInfo);
            Threading.WindowInfo = window.WindowInfo;

            keys = new List<Keys>();

            // Make the foreground context the current context
            if (GraphicsContext.CurrentContext == null || !GraphicsContext.CurrentContext.IsCurrent)
                window.MakeCurrent();

            // mouse
            // TODO review this when opentk 1.1 is released
#if WINDOWS || LINUX
            Mouse.setWindows(window);
#else
            Mouse.UpdateMouseInfo(window.Mouse);
#endif

            //Default no resizing
            AllowUserResizing = false;
        }
Ejemplo n.º 7
0
 public SimpleUserInterface()
 {
     GameWindow=new GameWindow(512,512);
     GameWindow.Visible = true;
     GameWindow.ProcessEvents();
     GameWindow.MakeCurrent();
     Renderer=new SimpleRenderer();
     Renderer.Init();
 }
Ejemplo n.º 8
0
 public override void processmMessage()
 {
     _window.MakeCurrent();
     _window.ProcessEvents();
 }