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(); } } }
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(); } } }
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; } } } }
public void Main(string[] args) { Core.Initialize(); List <AgateDriverInfo> drivers = Registrar.DisplayDrivers; frmPerformanceTester frm = new frmPerformanceTester(); frm.Show(); Trace.Listeners.Add(new TextWriterTraceListener(Console.Out)); List <TestMethod> tests = new List <TestMethod>(); tests.Add(FilledRectTest); tests.Add(DrawRectTest); tests.Add(DrawSurfaceTestColored); tests.Add(DrawSurfaceTestPlain); tests.Add(StretchTestColored); tests.Add(StretchTestPlain); foreach (AgateDriverInfo info in drivers) { Trace.WriteLine(string.Format("Starting driver {0}...", info.FriendlyName)); Trace.Indent(); double fps; Display.Initialize((DisplayTypeID)info.DriverTypeID); Display.VSync = false; DisplayWindow wind = DisplayWindow.CreateWindowed("Performance Test", 300, 300); font = new FontSurface("Arial", 11); for (int i = 0; i < tests.Count; i++) { TestResult r = Execute(tests[i]); r.Driver = info.FriendlyName; frm.AddTestResult(r); } if (Display.CurrentWindow.IsClosed) { Display.Dispose(); frm.Dispose(); return; } Display.Dispose(); } frm.Visible = false; frm.ShowDialog(); }
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); } } }
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; } } } }
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(); } } }
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); } } }
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(); } } }
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; } } } }
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++; } } }
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(); } } }