Example #1
0
        public void CreateContext()
        {
            Address = Marshal.AllocHGlobal(sizeof(int) * 512 * sizeof(int) * 512);

            Context = Task.Run(() =>
            {
                GraphicsMode mode              = new GraphicsMode(DisplayDevice.Default.BitsPerPixel, 32);
                GameWindowFlags flags          = GameWindowFlags.Default | GameWindowFlags.UseVirtualKeys | GameWindowFlags.FixedWindow;
                OpenTK.WindowState windowstate = OpenTK.WindowState.Normal;

                GameWindowNative gamewindow = new GameWindowNative(screenSize, screenSize, mode, flags, 3, 3);
                gamewindow.VSync            = VSyncMode.On;

                ScreenQuad = CreateScreenQuad();
                ProgramID  = CreateShaderProgram();

                coords    = GL.GetUniformLocation(ProgramID, "coords");
                scale     = GL.GetUniformLocation(ProgramID, "scale");
                ridgedmul = GL.GetUniformLocation(ProgramID, "ridgedmul");
                sizeXY    = GL.GetUniformLocation(ProgramID, "sizeXY");
                seedID    = GL.GetUniformLocation(ProgramID, "seed");

                ErrorCode err = GL.GetError();
#if !DEBUG
                gamewindow.Visible = false;
#endif
                gamewindow.WindowState = windowstate;

                gamewindow.RenderFrame += (a, b) => OnRenderFrame(gamewindow, b, ct0);

                gamewindow.Closed += (a, b) =>
                {
                    ScreenQuad.Dispose();
                    if (ProgramID != 0)
                    {
                        GL.DeleteProgram(ProgramID);
                    }
                    Marshal.FreeHGlobal(Address);
                    if (closedByUser)
                    {
                        CreateContext();
                    }
                };

                try
                {
                    gamewindow.Run();
                }
                catch (Exception)
                {
                }
            });
        }
Example #2
0
        private static WindowState OpenTKToVeldridState(OpenTK.WindowState openTKState, WindowBorder border)
        {
            switch (openTKState)
            {
            case OpenTK.WindowState.Normal:
                return(border == WindowBorder.Hidden ? WindowState.BorderlessFullScreen : WindowState.Normal);

            case OpenTK.WindowState.Minimized:
                return(WindowState.Minimized);

            case OpenTK.WindowState.Maximized:
                return(WindowState.Maximized);

            case OpenTK.WindowState.Fullscreen:
                return(WindowState.FullScreen);

            default:
                throw Illegal.Value <WindowState>();
            }
        }