Ejemplo n.º 1
0
 protected override void OnRenderFrame(FrameEventArgs e)
 {
     // called once per frame; render
     game.Tick();
     GL.BindTexture(TextureTarget.Texture2D, screenID);
     GL.TexImage2D(TextureTarget.Texture2D,
                   0,
                   PixelInternalFormat.Rgba,
                   game.screen.width,
                   game.screen.height,
                   0,
                   OpenTK.Graphics.OpenGL.PixelFormat.Bgra,
                   PixelType.UnsignedByte,
                   game.screen.pixels
                   );
     GL.Clear(ClearBufferMask.ColorBufferBit);
     GL.MatrixMode(MatrixMode.Modelview);
     GL.LoadIdentity();
     GL.BindTexture(TextureTarget.Texture2D, screenID);
     GL.Begin(PrimitiveType.Quads);
     GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(-1.0f, -1.0f);
     GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(1.0f, -1.0f);
     GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(1.0f, 1.0f);
     GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(-1.0f, 1.0f);
     GL.End();
     game.Render();
     SwapBuffers();
 }
Ejemplo n.º 2
0
        private void timerRender_Tick(object sender, EventArgs e)
        {
            BufferedGraphicsContext context  = BufferedGraphicsManager.Current;
            BufferedGraphics        graphics = context.Allocate(this.CreateGraphics(), new Rectangle(0, 0, ScreenWidth, ScreenHeight));

            GameOfLife.Render(graphics.Graphics);

            graphics.Render(this.CreateGraphics());
            graphics.Dispose();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            (int width, int height, int maxFps) = MainMenu();
            Stopwatch sw        = new Stopwatch();
            long      frameWait = Stopwatch.Frequency / maxFps;

            var game = new Game(width, height);

            game.RandomSeed();
            var running = true;
            var wrap    = true;

            while (running)
            {
                sw.Restart();
                if (wrap)
                {
                    game.TickWrap();
                }
                else
                {
                    game.Tick();
                }

                game.Render();
                do
                {
                    if (Console.KeyAvailable)
                    {
                        ConsoleKey key = Console.ReadKey(true).Key;
                        switch (key)
                        {
                        case ConsoleKey.Escape:
                            running = false;
                            break;

                        case ConsoleKey.Enter:
                            game.RandomSeed();
                            break;

                        case ConsoleKey.Spacebar:
                            wrap = !wrap;
                            break;

                        case ConsoleKey.Tab:
                            NextColor();
                            break;
                        }
                    }
                } while (sw.ElapsedTicks < frameWait);
            }
        }