Exemple #1
0
        private void OnRenderFrame(GameWindowNative window, FrameEventArgs args, CancellationToken ct0)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit);

            GL.UseProgram(ProgramID);
            GL.Uniform2(coords, xCoord, yCoord);
            GL.Uniform1(seedID, (float)seed % int.MaxValue);
            GL.Uniform4(scale, 1f / 128f, 1f / 512f, 1f / 256f, 1f / 720f);
            GL.Uniform1(ridgedmul, 8.0f);
            GL.Uniform1(sizeXY, screenSize);

            RenderScreenQuad();

            GL.UseProgram(0);

            window.SwapBuffers();

            WritePtr();

            if (ct0.IsCancellationRequested)
            {
                window.Close();
                window.Dispose();
            }
        }
Exemple #2
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)
                {
                }
            });
        }