Esempio n. 1
0
        public void Main(string [] args)
        {
            var tgz = new TgzFileProvider("Data/dogs.tar.gz");

            using (AgateSetup setup = new AgateSetup())
            {
                setup.AskUser = true;
                setup.Initialize(true, false, false);
                if (setup.WasCanceled)
                {
                    return;
                }

                DisplayWindow wind = DisplayWindow.CreateWindowed(
                    "TgzFileProvider Tester", 800, 600, false);

                Surface surf  = new Surface(tgz, "dogs.png");
                Surface surf2 = new Surface(tgz, "bigpaddle.png");

                PixelBuffer pix = surf.ReadPixels();

                while (wind.IsClosed == false)
                {
                    Display.BeginFrame();
                    Display.Clear(Color.Blue);

                    surf.Draw();
                    surf2.Draw(10, 490);

                    Display.EndFrame();
                    Core.KeepAlive();
                }
            }
        }
Esempio n. 2
0
        public void Main(string[] args)
        {
            using (AgateSetup setup = new AgateSetup(args))
            {
                setup.AskUser = true;
                setup.Initialize(true, false, false);
                if (setup.WasCanceled)
                {
                    return;
                }

                frm = new PixelBufferForm();
                frm.Show();

                DisplayWindow wind = new DisplayWindow(CreateWindowParams.FromControl(frm.panel1));

                image  = new Surface("9ball.png");
                buffer = image.ReadPixels(PixelFormat.RGBA8888);

                Mouse.MouseDown += new InputEventHandler(Mouse_MouseDown);
                Mouse.MouseMove += new InputEventHandler(Mouse_MouseMove);

                while (wind.IsClosed == false)
                {
                    Display.BeginFrame();
                    Display.Clear();

                    image.Draw(imageLocation);

                    Display.EndFrame();
                    Core.KeepAlive();
                }
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            using (AgateSetup setup = new AgateSetup(args))
            {
                // initialize AgateLib.
                setup.InitializeAll();
                // if something bad happened, bail out.
                if (setup.WasCanceled)
                {
                    return;
                }
                // Create a window with resolution 640x480 and title "Hello World"
                DisplayWindow wind = DisplayWindow.CreateWindowed("Hello World", 640, 480);
                // Run the program while the window is open.
                while (Display.CurrentWindow.IsClosed == false)
                {
                    // Display.BeginFrame must be called at the start of every frame,
                    // before rendering takes place.
                    Display.BeginFrame();
                    // Clears the display to a nice color.
                    Display.Clear(Color.DarkGreen);
                    // End frame must be called after all drawing is finished.
                    Display.EndFrame();

                    // KeepAlive processes events.
                    Core.KeepAlive();
                }
            }
        }
Esempio n. 4
0
        public void Main(string[] args)
        {
            frmSurfaceTester form = new frmSurfaceTester();

            using (AgateSetup displaySetup = new AgateSetup(args))
            {
                displaySetup.AskUser = true;
                displaySetup.Initialize(true, false, false);
                if (displaySetup.WasCanceled)
                {
                    return;
                }

                form.Show();

                int frame = 0;

                while (form.Visible)
                {
                    form.UpdateDisplay();

                    frame++;
                }
            }
        }
Esempio n. 5
0
        public void Main(string[] args)
        {
            frmSpriteTester form = new frmSpriteTester();

            AgateSetup displaySetup = new AgateSetup(args);

            using (displaySetup)
            {
                displaySetup.Initialize(true, false, false);
                if (displaySetup.WasCanceled)
                {
                    return;
                }

                form.Show();

                while (form.Visible)
                {
                    form.UpdateDisplay();

                    //System.Threading.Thread.Sleep(10);
                    Core.KeepAlive();
                }
            }
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            using (AgateSetup setup = new AgateSetup(args))
            {
                // initialize AgateLib.
                setup.InitializeAll();
                // if something bad happened, bail out.
                if (setup.WasCanceled)
                    return;
                // Create a window with resolution 640x480 and title "Hello World"
                DisplayWindow wind = DisplayWindow.CreateWindowed("Hello World", 640, 480);
                // Run the program while the window is open.
                while (Display.CurrentWindow.IsClosed == false)
                {
                    // Display.BeginFrame must be called at the start of every frame,
                    // before rendering takes place.
                    Display.BeginFrame();
                    // Clears the display to a nice color.
                    Display.Clear(Color.DarkGreen);
                    // End frame must be called after all drawing is finished.
                    Display.EndFrame();

                    // KeepAlive processes events.
                    Core.KeepAlive();
                }

            }
        }
Esempio n. 7
0
        public void Main(string[] args)
        {
            using (AgateSetup setup = new AgateSetup(args))
            {
                setup.Initialize(true, false, false);

                if (setup.WasCanceled)
                {
                    return;
                }

                DisplayWindow wind = DisplayWindow.CreateWindowed("Rotating sprite", 300, 300);
                Sprite        sp   = new Sprite("spike.png", 16, 16);

                sp.RotationCenter   = OriginAlignment.Center;
                sp.DisplayAlignment = OriginAlignment.Center;

                sp.RotationAngleDegrees = 90;
                sp.SetScale(2, 2);

                Point location = new Point(150, 100);

                while (wind.IsClosed == false)
                {
                    Display.BeginFrame();
                    Display.Clear(Color.DarkRed);

                    sp.RotationAngleDegrees += 180 * Display.DeltaTime / 1000.0;
                    sp.Draw(location);

                    Display.DrawRect(location.X, location.Y, 1, 1, Color.YellowGreen);

                    Display.EndFrame();
                    Core.KeepAlive();

                    if (Keyboard.Keys[KeyCode.F5])
                    {
                        if (wind.IsFullScreen)
                        {
                            wind.SetWindowed();
                            wind.Size = new Size(500, 500);
                        }
                        else
                        {
                            wind.SetFullScreen(800, 600, 32);
                        }

                        Keyboard.ReleaseKey(KeyCode.F5);
                    }
                    if (Keyboard.Keys[KeyCode.Escape])
                    {
                        return;
                    }
                }
            }
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            using (var setup = new AgateSetup(args))
            {
                setup.CreateDisplayWindow = false;
                setup.InitializeAgateLib();

                System.Windows.Forms.Application.Run(new frmSpriteCreator());
            }
        }
Esempio n. 9
0
        public void Main(string[] args)
        {
            using (AgateSetup setup = new AgateSetup())
            {
                setup.AskUser = true;
                setup.Initialize(true, false, false);
                if (setup.WasCanceled)
                {
                    return;
                }

                DisplayWindow wind           = DisplayWindow.CreateWindowed("Hello", 800, 600);
                Surface       someSurface    = new Surface("wallpaper.png");
                Surface       captureSurface = new Surface(1600, 1200);
                bool          capturing      = false;

                while (wind.IsClosed == false)
                {
                    if (Keyboard.Keys[KeyCode.C])
                    {
                        capturing = true;
                        Keyboard.ReleaseKey(KeyCode.C);
                    }
                    if (capturing)
                    {
                        Display.RenderTarget = captureSurface;
                        someSurface.SetScale(2, 2);
                    }

                    Display.BeginFrame();

                    Display.Clear(Color.White);

                    someSurface.Draw();

                    Display.EndFrame();

                    if (capturing)
                    {
                        captureSurface.SaveTo("CapturedImage.png", ImageFileFormat.Png);
                        Display.RenderTarget = wind;
                        someSurface.SetScale(1, 1);
                        capturing = false;

                        Debug.Print("Captured image to CapturedImage.png");
                    }

                    Core.KeepAlive();
                    System.Threading.Thread.Sleep(10);
                }
            }
        }
Esempio n. 10
0
        public void Main(string[] args)
        {
            using (AgateSetup setup = new AgateSetup())
            {
                setup.AskUser = true;
                setup.Initialize(true, false, false);
                if (setup.WasCanceled)
                {
                    return;
                }

                DisplayWindow wind = DisplayWindow.CreateWindowed("Font Line Tester", 640, 480);
                Keyboard.KeyDown += new InputEventHandler(Keyboard_KeyDown);
                Core.AutoPause    = true;

                // TODO: Fix this
                //FontSurface bmpFont = FontSurface.LoadBitmapFont("bitmapfont.png", "bitmapfont.xml");

                //fonts.Add(bmpFont);
                fonts.Add(new FontSurface("Arial", 12));
                fonts.Add(new FontSurface("Arial", 20));
                fonts.Add(new FontSurface("Times", 12));
                fonts.Add(new FontSurface("Times", 20));
                fonts.Add(new FontSurface("Tahoma", 14));
                fonts.Add(new FontSurface("Comic", 16));

                while (wind.IsClosed == false)
                {
                    Display.BeginFrame();
                    Display.Clear(Color.Navy);

                    Rectangle drawRect;

                    FontTests(fonts[currentFont], out drawRect);

                    Display.DrawRect(drawRect, Color.Red);

                    //bmpFont.DrawText(0, 370, "Use numeric keypad to switch fonts.");
                    //bmpFont.DrawText(0, 400,
                    //    "Measured size was: " + drawRect.Size.ToString());

                    Display.EndFrame();
                    Core.KeepAlive();

                    if (Keyboard.Keys[KeyCode.Escape])
                    {
                        return;
                    }
                }
            }
        }
Esempio n. 11
0
        static void Main(string[] args)
        {
            using (AgateSetup setup = new AgateSetup())
            {
                setup.InitializeDisplay(AgateLib.Drivers.DisplayTypeID.Reference);
                if (setup.WasCanceled)
                {
                    return;
                }

                System.Windows.Forms.Application.Run(new frmSpriteCreator());
                return;
            }
        }
Esempio n. 12
0
        public void Main(string[] args)
        {
            using (AgateSetup setup = new AgateSetup(args))
            {
                setup.AskUser = true;
                setup.Initialize(true, false, true);
                if (setup.WasCanceled)
                {
                    return;
                }

                new Form1().ShowDialog();
            }
        }
Esempio n. 13
0
        void Run(string[] args)
        {
            using (AgateSetup setup = new AgateSetup(args))
            {
                setup.Initialize(true, false, false);
                if (setup.WasCanceled)
                {
                    return;
                }

                DisplayWindow wind = DisplayWindow.CreateWindowed
                                         ("Pong Example", displayWidth, displayHeight);

                font = new FontSurface("Sans Serif", 14);

                paddle[0]    = new Vector2(50, displayHeight / 2);
                paddle[1]    = new Vector2(playAreaWidth - 50 - paddleWidth, displayHeight / 2);
                ball         = new Vector2(playAreaWidth / 2, displayHeight / 2);
                ballvelocity = new Vector2(-70, 70);

                while (wind.IsClosed == false)
                {
                    Display.BeginFrame();
                    Display.Clear(Color.DarkGray);

                    DrawBorder();
                    DrawPaddles();
                    DrawBall();
                    DrawScore();

                    Display.EndFrame();
                    Core.KeepAlive();

                    if (Keyboard.Keys[KeyCode.Escape])
                    {
                        wind.Dispose();
                    }

                    float time_s = (float)Display.DeltaTime / 1000.0f;

                    UpdatePaddles(time_s);
                    UpdateBall(time_s);
                }
            }
        }
Esempio n. 14
0
        public void Main(string[] args)
        {
            using (AgateSetup setup = new AgateSetup())
            {
                setup.AskUser = true;
                setup.Initialize(true, false, false);
                if (setup.WasCanceled)
                {
                    return;
                }

                Keyboard.KeyDown += new InputEventHandler(Keyboard_KeyDown);

                wind = DisplayWindow.CreateWindowed("Ortho Projection Test", 640, 480, false);

                Surface surf = new Surface("jellybean.png");
                surf.Color = Color.Cyan;

                while (wind.IsClosed == false)
                {
                    Display.BeginFrame();
                    Display.Clear();

                    switch (ortho)
                    {
                    case 1:
                        Display.SetOrthoProjection(0, 0, surf.SurfaceWidth * 2, surf.SurfaceHeight * 2);
                        break;

                    case 2:
                        Display.SetOrthoProjection(-surf.SurfaceWidth, -surf.SurfaceHeight,
                                                   surf.SurfaceWidth, surf.SurfaceHeight);
                        break;
                    }

                    Display.FillRect(-2, -2, 4, 4, Color.Red);

                    surf.Draw();

                    Display.EndFrame();

                    Core.KeepAlive();
                }
            }
        }
Esempio n. 15
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            using (AgateSetup setup = new AgateSetup())
            {

                setup.Initialize(true, false, false);
                if (setup.WasCanceled) return;

                mainFrm frm = new mainFrm();
                frm.Show();

                DisplayWindow window = DisplayWindow.CreateFromControl(frm.pictureBox1);

                while (!window.IsClosed)
                {
                    Display.BeginFrame();
                    Display.Clear(Color.White);

                    if (frm.grid != null)
                    {
                        int rec = frm.pictureBox1.Width / frm.grid.Size;
                        for (int y = 0; y < frm.grid.Size; y++)
                        {
                            for (int x = 0; x < frm.grid.Size; x++)
                            {
                                Display.FillRect(new Rectangle(x * rec, y * rec, rec, rec),
                                    Color.FromArgb(frm.grid.Cells[y, x].Owner.Color.R, frm.grid.Cells[y, x].Owner.Color.G,
                                        frm.grid.Cells[y, x].Owner.Color.B));
                            }
                        }
                    }

                    Display.EndFrame();
                    Core.KeepAlive();
                    Thread.Sleep(1);
                }

            }

            //Application.Run(new mainFrm());
        }
Esempio n. 16
0
        public void Main(string[] args)
        {
            using (AgateSetup setup = new AgateSetup(args))
            {
                setup.AskUser = true;
                setup.Initialize(true, false, false);
                if (setup.WasCanceled)
                {
                    return;
                }

                DisplayWindow wind = DisplayWindow.CreateWindowed(
                    "Bitmap Font Tester", 800, 600, false);

                Display.BeginFrame();
                Display.Clear(Color.Navy);
                Display.EndFrame();
                Core.KeepAlive();

                BitmapFontOptions fontOptions = new BitmapFontOptions("Times", 18, FontStyle.Bold);
                fontOptions.UseTextRenderer = true;

                FontSurface font = new FontSurface(fontOptions);

                // TODO: Fix this
                //font.Save("testfont.xml");


                //FontSurface second = FontSurface.LoadBitmapFont("testfont.png", "testfont.xml");

                while (wind.IsClosed == false)
                {
                    Display.BeginFrame();
                    Display.Clear(Color.Navy);

                    font.DrawText("The quick brown fox jumps over the lazy dog.");

                    //second.DrawText(0, font.StringDisplayHeight("M"), "The quick brown fox jumps over the lazy dog.");

                    Display.EndFrame();
                    Core.KeepAlive();
                }
            }
        }
Esempio n. 17
0
        public void Main(string[] args)
        {
            using (AgateSetup setup = new AgateSetup())
            {
                setup.AskUser = true;
                setup.Initialize(true, false, false);
                if (setup.WasCanceled)
                {
                    return;
                }

                frmTileTester frm = new frmTileTester();
                frm.Show();

                tile = new Surface("bg-bricks.png");

                Display.VSync = true;
                while (frm.IsDisposed == false)
                {
                    Display.BeginFrame();
                    Display.Clear(Color.FromArgb(255, 0, 255));

                    DrawTiles();

                    Display.EndFrame();
                    Core.KeepAlive();

                    if (frm.ScrollX)
                    {
                        xval += (float)Display.DeltaTime / 20.0f;
                    }
                    if (frm.ScrollY)
                    {
                        // move at 50 pixels per second
                        yval += (float)Display.DeltaTime / 20.0f;
                    }
                }
            }
        }
Esempio n. 18
0
        public void Main(string[] args)
        {
            using (AgateSetup setup = new AgateSetup("Resource Tester", args))
            {
                setup.InitializeAll();
                if (setup.WasCanceled)
                {
                    return;
                }

                AgateFileProvider.Resources.Add(new AgateLib.Utility.FileSystemProvider("Data"));

                AgateResourceCollection resources = new AgateResourceCollection("TestResourceFile.xml");

                DisplayWindow wind   = new DisplayWindow(resources, "main_window");
                Surface       surf   = new Surface(resources, "sample_surf");
                ISprite       sprite = new Sprite(resources, "sample_sprite");
                FontSurface   font   = new FontSurface(resources, "sample_font");

                sprite.StartAnimation();

                while (wind.IsClosed == false)
                {
                    Display.BeginFrame();
                    Display.Clear(Color.Red);

                    font.DrawText(0, 0, "FPS: " + Display.FramesPerSecond.ToString());

                    surf.Draw(20, 20);

                    sprite.Update();
                    sprite.Draw(100, 100);

                    Display.EndFrame();
                    Core.KeepAlive();
                }
            }
        }
Esempio n. 19
0
        public void Main(string[] args)
        {
            using (AgateSetup setupDisplay = new AgateSetup())
            {
                setupDisplay.AskUser = true;
                setupDisplay.Initialize(true, false, false);

                if (setupDisplay.WasCanceled)
                {
                    return;
                }

                DisplayWindow wind = DisplayWindow.CreateWindowed("Font Tester", 800, 600);

                FontSurface font       = new FontSurface("Sans Serif", 12);
                FontSurface bitmapFont = FontSurface.BitmapMonospace("lotafont.png", new Size(16, 16));

                int frame = 0;


                while (wind.IsClosed == false)
                {
                    Display.BeginFrame();
                    Display.Clear(Color.DarkGray);


                    // test the color changing
                    font.Color = Color.LightGreen;
                    font.DrawText(20, 150, "This is regular green text.");
                    font.Color = Color.White;

                    // test display alignment property
                    Point  textPoint = new Point(100, 50);
                    string text      = string.Format("This text is centered on {0},{1}.", textPoint.X, textPoint.Y);
                    Size   textSize  = font.StringDisplaySize(text);

                    // draw a box around where the text should be displayed.
                    Display.DrawRect(new Rectangle(textPoint.X - textSize.Width / 2, textPoint.Y - textSize.Height / 2,
                                                   textSize.Width, textSize.Height), Color.Gray);

                    font.DisplayAlignment = OriginAlignment.Center;
                    font.DrawText(textPoint, text);
                    font.DisplayAlignment = OriginAlignment.TopLeft;

                    // test text scaling
                    font.SetScale(2.0, 2.0);
                    text      = "This text is twice as big.";
                    textPoint = new Point(50, 75);
                    textSize  = font.StringDisplaySize(text);

                    // draw a box with the same size the text should appear as
                    Display.DrawRect(new Rectangle(textPoint, textSize), Color.White);

                    font.DrawText(textPoint, text);
                    font.SetScale(1.0, 1.0);

                    // this draws a white background behind the text we want to Display.
                    text  = "F2: Toggle VSync   F5:  Toggle Windowed / Fullscreen      ";
                    text += "FPS: " + Display.FramesPerSecond.ToString("0.00") + "    ";

                    if (Core.IsActive)
                    {
                        text += "Active";
                    }
                    else
                    {
                        text += "Not Active";
                    }

                    // figure out how big the displayed text will be
                    textSize = font.StringDisplaySize(text);

                    // draw the white background
                    Display.FillRect(new Rectangle(new Point(0, 0), textSize), Color.White);

                    // draw the text on top of the background
                    font.Color = Color.Black;
                    font.DrawText(text);  // supplying no position arguments defaults to (0, 0)

                    // draw something which moves to let us know the program is running
                    Display.FillRect(new Rectangle(
                                         10, 200, 70 + (int)(50 * Math.Cos(frame / 10.0)), 50), Color.Red);

                    // do some bitmap font stuff
                    bitmapFont.DrawText(10, 350, "THIS IS BITMAP FONT TEXT.");

                    bitmapFont.Color = Color.Red;
                    bitmapFont.DrawText(10, 366, "THIS IS RED TEXT.");
                    bitmapFont.Color = Color.White;

                    bitmapFont.SetScale(3, 2);
                    bitmapFont.DrawText(10, 382, "THIS IS BIGG.");
                    bitmapFont.SetScale(1, 1);

                    Display.FillRect(new Rectangle(95, 425, 10, 10), Color.Blue);
                    bitmapFont.DisplayAlignment = OriginAlignment.Center;
                    bitmapFont.DrawText(100, 430, "CHECK");
                    bitmapFont.DisplayAlignment = OriginAlignment.TopLeft;

                    Display.FillRect(new Rectangle(-10, -10, 20, 20), Color.Green);

                    // and we're done.
                    Display.EndFrame();
                    Core.KeepAlive();

                    frame++;

                    // toggle full screen if the user pressed F5;
                    if (Keyboard.Keys[KeyCode.F5])
                    {
                        System.Diagnostics.Debug.Print("IsFullscreen: {0}", Display.CurrentWindow.IsFullScreen);

                        if (Display.CurrentWindow.IsFullScreen == false)
                        {
                            Display.CurrentWindow.SetFullScreen(800, 600, 32);
                        }
                        else
                        {
                            Display.CurrentWindow.SetWindowed();
                        }

                        System.Diagnostics.Debug.Print("IsFullscreen: {0}", Display.CurrentWindow.IsFullScreen);
                    }
                    else if (Keyboard.Keys[KeyCode.F2])
                    {
                        Display.VSync = !Display.VSync;
                        Keyboard.ReleaseKey(KeyCode.F2);
                    }
                    else if (Keyboard.Keys[KeyCode.Escape])
                    {
                        Display.Dispose();
                        return;
                    }
                }
            }
        }
Esempio n. 20
0
        public void Main(string[] args)
        {
            using (AgateSetup setup = new AgateSetup(args))
            {
                setup.AskUser = true;
                setup.Initialize(true, false, false);
                if (setup.WasCanceled)
                {
                    return;
                }

                LightingTestForm frm = new LightingTestForm();
                frm.Show();

                DisplayWindow wnd = new DisplayWindow(CreateWindowParams.FromControl(frm.agateRenderTarget1));

                Surface image = new Surface("jellybean.png");
                Surface ball  = new Surface("ball.png");
                Point   ballPt;
                double  time = 0;

                image.SetScale(2.0, 2.0);
                ball.DisplayAlignment = OriginAlignment.Center;

                LightManager lights = new LightManager();
                lights.Enabled = true;
                lights.AddPointLight(new Vector3(0, 0, -1), Color.White);
                lights.AddPointLight(new Vector3(0, 0, -1), Color.Yellow);

                Display.VSync = false;

                //lights[0].Ambient = Color.White;
                lights[1].AttenuationConstant  = 0.01f;
                lights[1].AttenuationQuadratic = 5e-7f;

                Mouse.MouseMove += delegate(InputEventArgs e)
                {
                    lights[1].Position =
                        new Vector3(e.MousePosition.X, e.MousePosition.Y, -1);
                };

                while (frm.Visible == true)
                {
                    if (frm.chkMoveLight.Checked)
                    {
                        time += Display.DeltaTime / 1000.0;
                    }


                    ballPt = new Point((int)(120 + 110 * Math.Cos(time)),
                                       (int)(120 + 110 * Math.Sin(time)));

                    lights[0].Position = new Vector3(ballPt.X, ballPt.Y, -1);
                    lights[0].Ambient  = Color.FromArgb(frm.btnAmbient.BackColor.ToArgb());
                    lights[0].Diffuse  = Color.FromArgb(frm.btnDiffuse.BackColor.ToArgb());

                    image.RotationAngleDegrees = (double)frm.nudAngle.Value;

                    Display.BeginFrame();
                    Display.Clear(Color.DarkRed);

                    lights.Enabled = frm.enableLightingCheck.Checked;
                    lights.DoLighting();

                    if (frm.chkSurfaceGradient.Checked)
                    {
                        Gradient g = new Gradient(Color.Red, Color.Blue, Color.Cyan, Color.Green);

                        image.ColorGradient = g;
                    }
                    else
                    {
                        image.Color = Color.White;
                    }

                    image.TesselateFactor = (int)frm.nudTess.Value;

                    image.Draw(50, 50);

                    image.Draw(50 + image.DisplayWidth, 50);
                    image.Draw(50, 50 + image.DisplayHeight);

                    ball.Draw(ballPt);

                    Display.EndFrame();
                    Core.KeepAlive();

                    frm.lblFPS.Text = "FPS: " + Display.FramesPerSecond.ToString("0.00");
                }
            }
        }
Esempio n. 21
0
        public static void Start(bool debugMode)
        {
            IDTDeterministicRandom rng = new DTDeterministicRandom(seed: 0);

            using (AgateSetup setup = new AgateSetup())
            {
                setup.InitializeDisplay();
                setup.InitializeInput();
                bool canSuccessfullyPlayAudio;
                try
                {
                    setup.InitializeAudio();
                    canSuccessfullyPlayAudio = true;
                }
                catch (Exception)
                {
                    canSuccessfullyPlayAudio = false;
                }

                if (setup.WasCanceled)
                {
                    return;
                }

                DisplayWindow window = DisplayWindow.CreateWindowed("DT Danmaku", 1000, 700);
                Display.VSync = false;

                int fps = 60;

                IFrame <IDTDanmakuAssets> frame = DTDanmaku.GetFirstFrame(
                    fps: fps,
                    rng: rng,
                    guidGenerator: new GuidGenerator(guidString: "285419206161623102"),
                    debugMode: debugMode);

                IKeyboard agateLibKeyboard          = new AgateLibKeyboard();
                IMouse    agateLibMouse             = new AgateLibMouse();
                IDisplay <IDTDanmakuAssets> display = new DTDanmakuAgateLibDisplay(canSuccessfullyPlayAudio: canSuccessfullyPlayAudio);
                IKeyboard prevKeyboard = new EmptyKeyboard();
                IMouse    prevMouse    = new EmptyMouse();

                double elapsedTimeMs = 0.0;

                long timeForFpsCounter       = DateTime.Now.Ticks;
                int  currentDisplayFpsCount  = 0;
                int  displayFpsSnapshotValue = 0;

                int debugSlowDown        = 0;
                int debugNumCyclesToSkip = 0;

                int numTimesFramesDropped = 0;

                while (Display.CurrentWindow.IsClosed == false)
                {
                    Display.BeginFrame();

                    Display.Clear(Color.White);

                    frame.Render(display);

                    elapsedTimeMs += Display.DeltaTime;

                    // Run at 60 frames per second.

                    // If for whatever reason, we're really behind, we'll try to catch up,
                    // but only for a maximum of 5 consecutive frames.
                    if (elapsedTimeMs > 1000.0 / fps * 5.0)
                    {
                        elapsedTimeMs = 1000.0 / fps * 5.0;

                        numTimesFramesDropped++;
                    }

                    if (elapsedTimeMs > 1000.0 / fps)
                    {
                        if (debugMode)
                        {
                            if (agateLibKeyboard.IsPressed(Key.Six) && !prevKeyboard.IsPressed(Key.Six))
                            {
                                debugSlowDown = (debugSlowDown + 1) % 4;
                            }
                        }

                        elapsedTimeMs = elapsedTimeMs - 1000.0 / fps;
                        IKeyboard currentKeyboard = new CopiedKeyboard(agateLibKeyboard);
                        IMouse    currentMouse    = new CopiedMouse(agateLibMouse);

                        if (debugMode)
                        {
                            if (debugNumCyclesToSkip == 0)
                            {
                                frame = frame.GetNextFrame(currentKeyboard, currentMouse, prevKeyboard, prevMouse, display);
                            }
                        }
                        else
                        {
                            frame = frame.GetNextFrame(currentKeyboard, currentMouse, prevKeyboard, prevMouse, display);
                        }


                        prevKeyboard = new CopiedKeyboard(currentKeyboard);
                        prevMouse    = new CopiedMouse(currentMouse);

                        if (debugMode)
                        {
                            if (debugSlowDown > 0)
                            {
                                if (debugNumCyclesToSkip > 0)
                                {
                                    debugNumCyclesToSkip--;
                                }
                                else
                                {
                                    if (debugSlowDown == 1)
                                    {
                                        debugNumCyclesToSkip = 1;
                                    }
                                    if (debugSlowDown == 2)
                                    {
                                        debugNumCyclesToSkip = 7;
                                    }
                                    if (debugSlowDown == 3)
                                    {
                                        debugNumCyclesToSkip = 31;
                                    }
                                }
                            }
                            else
                            {
                                debugNumCyclesToSkip = 0;
                            }
                        }
                    }
                    else
                    {
                        System.Threading.Thread.Sleep(millisecondsTimeout: 5);
                    }

                    if (debugMode)
                    {
                        currentDisplayFpsCount++;
                        long milliSecondsElapsedForFpsCounter = (DateTime.Now.Ticks - timeForFpsCounter) / 10000L;
                        if (milliSecondsElapsedForFpsCounter > 1000)
                        {
                            timeForFpsCounter      += 10000L * 1000L;
                            displayFpsSnapshotValue = currentDisplayFpsCount;
                            currentDisplayFpsCount  = 0;
                        }
                        display.DebugPrint(x: 10, y: 10, debugText: "fps: " + displayFpsSnapshotValue.ToString(CultureInfo.InvariantCulture));

                        display.DebugPrint(x: 10, y: 70, debugText: "num frames dropped: " + numTimesFramesDropped.ToString(CultureInfo.InvariantCulture));
                    }

                    Display.EndFrame();

                    Core.KeepAlive();
                }
            }
        }
Esempio n. 22
0
        public void Main(string[] args)
        {
            using (AgateSetup setup = new AgateSetup(args))
            {
                // create a random number generation object
                // so that we can make pretty colors.
                Random rand = new Random();

                // initialize the display, asking the user what display driver to use.
                setup.AskUser = true;
                setup.Initialize(true, false, false);

                // normally, the display should initialize fine, and goahead will be true.
                // However, here we are asking the user what display mode they want to pick,
                // and they may push the cancel button.  If they do, then exit the program.
                if (setup.WasCanceled)
                {
                    return;
                }

                frm = new DrawingTester();

                frm.btnClear.Click      += new EventHandler(btnClear_Click);
                frm.btnDrawLine.Click   += new EventHandler(btnDrawLine_Click);
                frm.btnDrawRect.Click   += new EventHandler(btnDrawRect_Click);
                frm.btnFillRect.Click   += new EventHandler(btnFillRect_Click);
                frm.btnDrawCircle.Click += new EventHandler(btnDrawCircle_Click);
                frm.Show();

                // This creates the window that we will be drawing in.
                // 640x480 are the dimensions of the screen area that we will write to
                DisplayWindow wind = DisplayWindow.CreateFromControl(frm.panel1);

                while (wind.IsClosed == false)
                {
                    // Display.BeginFrame must be called before any rendering takes place.
                    Display.BeginFrame();

                    // Clear back buffer
                    Display.Clear();

                    // draw shapes
                    foreach (Shape s in shapes)
                    {
                        s.Draw();
                    }

                    // Display.EndFrame must be called after rendering is done
                    // in order to actually update the display.
                    Display.EndFrame();

                    // Core.KeepAlive is where we play nice window the OS,
                    // allowing events to be processed and such.
                    // This is also required to process events that happen in our OWN
                    // code (ie. user input), so be sure to call this once a frame.
                    Core.KeepAlive();

                    // This gives a nice 1 second delay between each frame.
                    // Using the Sleep() call causes this application to
                    // relinquish CPU time.
                    System.Threading.Thread.Sleep(10);
                }
            }
        }
Esempio n. 23
0
        static void Main(string[] args)
        {
            using (AgateSetup setup = new AgateSetup("Tiling Test", args))
            {
                setup.AskUser = true;
                setup.Initialize(true, false, false);

                if (setup.WasCanceled)
                {
                    return;
                }

                DisplayWindow wnd = DisplayWindow.CreateWindowed("Tiling Test", 600, 600);

                int frame = 0;

                Surface[] tiles = new Surface[2];

                tiles[0] = new Surface("tile1.png");
                tiles[1] = new Surface("tile2.png");

                while (wnd.IsClosed == false)
                {
                    Display.BeginFrame();
                    Display.Clear(Color.FromArgb(
                                      (int)(128 * Math.Abs(Math.Cos(frame / 70.0))),
                                      (int)(128 * Math.Abs(Math.Sin(frame / 90.0))),
                                      (int)(128 * Math.Abs(Math.Sin(frame / 95.0)))));

                    int x = 0, y = 0;

                    tiles[0].SetScale(1, 1);
                    tiles[1].SetScale(1, 1);

                    for (int i = 0; i < wnd.Width / tiles[0].DisplayWidth; i++)
                    {
                        y = 0;

                        for (int j = 0; j < 4; j++)
                        {
                            int index = (i + j) % 2;

                            tiles[index].Draw(x, y);

                            y += tiles[0].DisplayHeight;
                        }

                        x += tiles[0].DisplayWidth;
                    }

                    double scale = 1.32;

                    tiles[0].SetScale(scale, scale);
                    tiles[1].SetScale(scale, scale);

                    x = 0;

                    for (int i = 0; i < wnd.Width / tiles[0].DisplayWidth; i++)
                    {
                        y = 200;

                        for (int j = 0; j < 4; j++)
                        {
                            int index = (i + j) % 2;

                            tiles[index].Draw(x, y);

                            y += tiles[0].DisplayHeight;
                        }

                        x += tiles[0].DisplayWidth;
                    }

                    Display.EndFrame();
                    Core.KeepAlive();

                    frame++;
                }
            }
        }
Esempio n. 24
0
        static void Main(string[] args)
        {
            using (AgateSetup setup = new AgateSetup(args))
            {
                setup.AskUser = true;
                setup.Initialize(true, false, false);
                if (setup.WasCanceled)
                {
                    return;
                }

                MultipleRenderTargetExample myForm = new MultipleRenderTargetExample();
                myForm.Show();

                // create three display windows
                DisplayWindow wnd_1 = DisplayWindow.CreateFromControl(myForm.pictureBox1);
                DisplayWindow wnd_2 = DisplayWindow.CreateFromControl(myForm.pictureBox2);
                DisplayWindow wnd_3 = DisplayWindow.CreateFromControl(myForm.pictureBox3);
                //DisplayWindow wnd_4 = new DisplayWindow(myForm.pictureBox4);

                // create a surface for drawing
                surf = new Surface(200, 150);

                // this is the code that will be called when the button is pressed
                myForm.btnDraw.Click         += new EventHandler(btnDraw_Click);
                myForm.btnClearSurface.Click += new EventHandler(btnClear_Click);

                while (myForm.Visible)
                {
                    // Render targets must be set before the call to BeginFrame,
                    // and may not be changed between BeginFrame and EndFrame.
                    Display.RenderTarget = wnd_1;

                    Display.BeginFrame();
                    Display.Clear(Color.Red);
                    Display.FillRect(new Rectangle(20, 20, 40, 30), Color.Blue);
                    Display.EndFrame();

                    // now do the second window.
                    Display.RenderTarget = wnd_2;

                    Display.BeginFrame();
                    Display.Clear(Color.Green);
                    Display.FillRect(new Rectangle(20, 20, 40, 30), Color.Yellow);
                    Display.EndFrame();

                    // draw the third window from the surface
                    Display.RenderTarget = wnd_3;

                    Display.BeginFrame();
                    Display.Clear(Color.Black);
                    surf.Draw(0, 0);
                    Display.EndFrame();

                    //Display.RenderTarget = wnd_4;
                    //Display.BeginFrame();
                    //Display.EndFrame();

                    Core.KeepAlive();
                    //System.Threading.Thread.Sleep(250);
                }
            }
        }