public override void shutdown() { base.shutdown(); _window.Close(); _window.Dispose(); }
private MyApplication() { //setup gameWindow = new GameWindow(700, 700); gameWindow.KeyDown += (s, arg) => gameWindow.Close(); gameWindow.Resize += (s, arg) => GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height); gameWindow.RenderFrame += GameWindow_RenderFrame; gameWindow.RenderFrame += (s, arg) => gameWindow.SwapBuffers(); //animation using a single SpriteSheet explosion = new SpriteSheetAnimation(new SpriteSheet(TextureLoader.FromBitmap(Resourcen.explosion), 5), 0, 24, 1); //animation using a bitmap for each frame alienShip = new AnimationTextures(.5f); //art from http://millionthvector.blogspot.de/p/free-sprites.html alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10001)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10002)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10003)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10004)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10005)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10006)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10007)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10008)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10009)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10010)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10011)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10012)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10013)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10014)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10015)); //for transparency in textures GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); //start game time timeSource.Start(); }
private MyApplication() { gameWindow = new GameWindow(); //gameWindow.WindowState = WindowState.Fullscreen; gameWindow.MouseMove += GameWindow_MouseMove; gameWindow.MouseWheel += GameWindow_MouseWheel; gameWindow.KeyDown += (s, arg) => gameWindow.Close(); gameWindow.Resize += (s, arg) => GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height); gameWindow.RenderFrame += (s, arg) => visual.Render(); gameWindow.RenderFrame += (s, arg) => gameWindow.SwapBuffers(); visual = new MainVisual(); }
private MyApplication() { //setup gameWindow = new GameWindow(700, 700); gameWindow.VSync = VSyncMode.On; gameWindow.KeyDown += (s, arg) => gameWindow.Close(); gameWindow.Resize += (s, arg) => GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height); gameWindow.RenderFrame += GameWindow_RenderFrame; gameWindow.RenderFrame += (s, arg) => gameWindow.SwapBuffers(); //background clear color GL.ClearColor(1, 1, 1, 1); }
private MyApplication() { //setup gameWindow = new GameWindow(512, 512); gameWindow.KeyDown += (s, arg) => gameWindow.Close(); gameWindow.Resize += (s, arg) => GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height); gameWindow.RenderFrame += GameWindow_RenderFrame; gameWindow.RenderFrame += (s, arg) => gameWindow.SwapBuffers(); texBackground = TextureLoader.FromBitmap(Resourcen.mountains); //background clear color GL.ClearColor(Color.White); }
private void Keyboard_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs e) { if (e.Key == OpenTK.Input.Key.F4 && keys.Contains(Keys.LeftAlt)) { window.Close(); return; } Keys xnaKey = KeyboardUtil.ToXna(e.Key); if (!keys.Contains(xnaKey)) { keys.Add(xnaKey); } }
private MyApplication() { //setup gameWindow = new GameWindow(700, 700); gameWindow.KeyDown += (s, arg) => gameWindow.Close(); gameWindow.Resize += (s, arg) => GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height); gameWindow.RenderFrame += GameWindow_RenderFrame; gameWindow.RenderFrame += (s, arg) => gameWindow.SwapBuffers(); //load font font = new TextureFont(TextureLoader.FromBitmap(Resourcen.Blood_Bath_2), 10, 32, .8f, 1, .7f); //background clear color GL.ClearColor(Color.Black); //for transparency in textures GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); }
private MyApplication() { //setup gameWindow = new GameWindow(700, 700); gameWindow.KeyDown += (s, arg) => gameWindow.Close(); gameWindow.Resize += (s, arg) => GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height); gameWindow.RenderFrame += GameWindow_RenderFrame; gameWindow.RenderFrame += (s, arg) => gameWindow.SwapBuffers(); texShip = TextureLoader.FromBitmap(Resourcen.redship4); texBackground = TextureLoader.FromBitmap(Resourcen.water); //background clear color GL.ClearColor(Color.White); //for transparency in textures we use blending GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); }
public void TestClear() { var pixel = new Pixel(); _window = new GameWindow(); _window.RenderFrame += (caller, args) => { GL.ReadBuffer(ReadBufferMode.Front); GL.ClearColor(0.4f, 0.2f, 1.0f, 1.0f); GL.Clear(ClearBufferMask.ColorBufferBit); _window.SwapBuffers(); pixel.ReadBuffer(0, 0); _window.Close(); }; _window.Run(); Assert.AreEqual(new Pixel(0.4f, 0.2f, 1.0f), pixel); }
private MyApplication() { //setup gameWindow = new GameWindow(700, 700); gameWindow.KeyDown += (s, arg) => gameWindow.Close(); gameWindow.Resize += (s, arg) => GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height); gameWindow.UpdateFrame += GameWindow_UpdateFrame; gameWindow.RenderFrame += GameWindow_RenderFrame; gameWindow.RenderFrame += (s, arg) => gameWindow.SwapBuffers(); queryA = new QueryObject(); queryB = new QueryObject(); //for query to work GL.Enable(EnableCap.DepthTest); }
private MyApplication() { var mode = new GraphicsMode(new ColorFormat(32), 24, 8, 0); gameWindow = new GameWindow(700, 700, mode, "Example", GameWindowFlags.Default, DisplayDevice.Default, 4, 3, GraphicsContextFlags.ForwardCompatible); gameWindow.WindowState = WindowState.Fullscreen; gameWindow.MouseMove += GameWindow_MouseMove; gameWindow.MouseWheel += GameWindow_MouseWheel; gameWindow.KeyDown += (s, arg) => gameWindow.Close(); gameWindow.Resize += (s, arg) => GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height); gameWindow.UpdateFrame += GameWindow_UpdateFrame; gameWindow.RenderFrame += GameWindow_RenderFrame; gameWindow.RenderFrame += (s, arg) => gameWindow.SwapBuffers(); model = new Model(); visual = new MainVisual(); }
static void Main(string[] args) { bool isRunning = true; Task.Factory.StartNew(() => { var win = new GameWindow(800, 600); win.RenderFrame += new EventHandler<FrameEventArgs>((o, e) => { if (UIThreadQueue.Instance.Any()) { var a = UIThreadQueue.Instance.Dequeue(); a(win); } }); win.UpdateFrame += new EventHandler<FrameEventArgs>((o, e) => { if (!isRunning) win.Close(); }); win.Closed += (o, e) => { isRunning = false; }; win.Run(); }); var map = Pycraft.Commanders.MapCommander.CreateMap(); Commanders.MapCommander.SetBlock(map, 0, 0, 0, 0); var mapCursor = Commanders.MapCursorCommander.CreateMapCursorForMap(map, 0, 0, 0); while (isRunning) { Drawing.Clear(); Commanders.MapCursorCommander.DrawCursor(mapCursor); Drawing.SwapBuffers(); }; }
private MyApplication() { //setup gameWindow = new GameWindow(700, 700); gameWindow.KeyDown += (s, arg) => gameWindow.Close(); gameWindow.Resize += (s, arg) => GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height); //callback for updating http://gameprogrammingpatterns.com/game-loop.html gameWindow.UpdateFrame += GameWindow_UpdateFrame; gameWindow.RenderFrame += GameWindow_RenderFrame; gameWindow.RenderFrame += (s, arg) => gameWindow.SwapBuffers(); texPlayer = TextureLoader.FromBitmap(Resourcen.bird1); //two landscape resources are available in the Resourcen.resx file texBackground = TextureLoader.FromBitmap(Resourcen.forest); //set how texture coordinates outside of [0..1] are handled texBackground.WrapMode(TextureWrapMode.Repeat); //background clear color GL.ClearColor(Color.White); //for transparency in textures GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); }
public void TestDrawQuad() { var pixel = new Pixel(); _window = new GameWindow {Width = 200, Height = 200}; _window.RenderFrame += (caller, args) => { GL.ReadBuffer(ReadBufferMode.Front); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Begin(PrimitiveType.Quads); { GL.Color3(1.0f, 1.0f, 1.0f); GL.Vertex2(0.0f, 0.0f); GL.Vertex2(-1.0f, 0.0f); GL.Vertex2(-1.0f, -1.0f); GL.Vertex2(0.0f, -1.0f); } GL.End(); _window.SwapBuffers(); pixel.ReadBuffer(0, 0); _window.Close(); }; _window.Run(); Assert.AreEqual(new Pixel(1.0f, 1.0f, 1.0f), pixel); }
private MyApplication() { //setup gameWindow = new GameWindow(700, 700); gameWindow.VSync = VSyncMode.On; gameWindow.KeyDown += (s, arg) => gameWindow.Close(); gameWindow.Resize += (s, arg) => GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height); gameWindow.UpdateFrame += GameWindow_UpdateFrame; gameWindow.RenderFrame += GameWindow_RenderFrame; gameWindow.RenderFrame += (s, arg) => gameWindow.SwapBuffers(); texBird = TextureLoader.FromBitmap(Resourcen.bird1); //background clear color GL.ClearColor(Color.DarkGreen); //for transparency in textures GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); //generate birds for(float delta = .1f; delta < .5f; delta += .1f) { birds.Add(Box2D.CreateFromCenterSize(rotCenter.X - delta, rotCenter.Y - delta, .1f, .1f)); birds.Add(Box2D.CreateFromCenterSize(rotCenter.X - delta, rotCenter.Y + delta, .1f, .1f)); birds.Add(Box2D.CreateFromCenterSize(rotCenter.X + delta, rotCenter.Y - delta, .1f, .1f)); birds.Add(Box2D.CreateFromCenterSize(rotCenter.X + delta, rotCenter.Y + delta, .1f, .1f)); } }
private static unsafe void SetupViewport() { int width = 800; int height = 600; GameWindow window = new GameWindow(width, height, OpenTK.Graphics.GraphicsMode.Default, "Mandelbrot", GameWindowFlags.Default); int tex; byte[] buffer = new byte[width * height * 4]; OpenTK.Graphics.IGraphicsContextInternal ctx = (OpenTK.Graphics.IGraphicsContextInternal)OpenTK.Graphics.GraphicsContext.CurrentContext; IntPtr contextHandle = ctx.Context.Handle; var mandelbrot = new MandelbrotCalculator(maxRecursionCount: 200, imageWidth: width, imageHeight: height); mandelbrot.Initialize(); GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest); GL.GenTextures(1, out tex); GL.BindTexture(TextureTarget.Texture2D, tex); mandelbrot.GetNextImageFrame(); mandelbrot.ReadResultBuffer(buffer); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, buffer); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat); bool isButtonPressed = false; bool changed = true; window.Mouse.ButtonDown += (s, e) => isButtonPressed = true; window.Keyboard.KeyDown += (s, e) => { if (e.Key == OpenTK.Input.Key.Escape) { window.Close(); } }; window.Mouse.ButtonUp += (s, e) => isButtonPressed = false; window.Mouse.Move += (s, e) => { if (isButtonPressed) { mandelbrot.CenterX -= e.XDelta / (double)mandelbrot.ImageWidth * mandelbrot.Width; mandelbrot.CenterY += e.YDelta / (double)mandelbrot.ImageHeight * mandelbrot.Height; changed = true; } }; window.Mouse.WheelChanged += (s, e) => { mandelbrot.Width /= Math.Pow(2, e.DeltaPrecise); mandelbrot.Height /= Math.Pow(2, e.DeltaPrecise); changed = true; }; window.UpdateFrame += (s, e) => { if (changed) { window.Title = string.Format("Mandelbrot: {0} + {1}i", mandelbrot.CenterX, mandelbrot.CenterY); mandelbrot.GetNextImageFrame(); mandelbrot.ReadResultBuffer(buffer); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, buffer); } changed = false; }; window.RenderFrame += (sender, e) => { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); DrawImage(tex, mandelbrot.ImageWidth, mandelbrot.ImageHeight); window.SwapBuffers(); }; window.VSync = VSyncMode.Off; window.Run(0); }
public void TestDrawTexture() { var pixels = new[] { new Pixel(), new Pixel(), new Pixel(), new Pixel() }; _window = new GameWindow { Width = 200, Height = 200 }; _window.RenderFrame += (caller, args) => { GL.Viewport(0, 0, 200, 200); GL.ReadBuffer(ReadBufferMode.Front); GL.Enable(EnableCap.Texture2D); int textureId = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, textureId); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); var bitmap = new Bitmap(@"..\..\Images\testtexture.png"); var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0); bitmap.UnlockBits(data); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Begin(PrimitiveType.Quads); { GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(-1.0f, -1.0f); GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(1.0f, -1.0f); GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(1.0f, 1.0f); GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(-1.0f, 1.0f); } GL.End(); _window.SwapBuffers(); pixels[0].ReadBuffer(99, 99); pixels[1].ReadBuffer(99, 100); pixels[2].ReadBuffer(100, 100); pixels[3].ReadBuffer(100, 99); _window.Close(); }; _window.Run(); Assert.AreEqual(new Pixel(1.0f, 0.0f, 0.0f), pixels[0]); Assert.AreEqual(new Pixel(0.0f, 1.0f, 0.0f), pixels[1]); Assert.AreEqual(new Pixel(0.0f, 0.0f, 1.0f), pixels[2]); Assert.AreEqual(new Pixel(0.0f, 0.0f, 0.0f), pixels[3]); }
public void TestSetModelViewMatrix() { var pixels = new[] { new Pixel(), new Pixel(), new Pixel(), new Pixel() }; _window = new GameWindow { Width = 200, Height = 200 }; _window.RenderFrame += (caller, args) => { GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Ortho(0.0, 2.0, 0.0, 2.0, 0.0, 4.0); GL.Viewport(0, 0, 200, 200); GL.MatrixMode(MatrixMode.Modelview); GL.ReadBuffer(ReadBufferMode.Front); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Color3(1.0f, 1.0f, 1.0f); DrawQuad(); GL.PushMatrix(); GL.Translate(0.0f, 1.0f, 0.0f); GL.Color3(1.0f, 0.0f, 0.0f); DrawQuad(); GL.PopMatrix(); GL.PushMatrix(); GL.Translate(1.0f, 1.0f, 0.0f); GL.Color3(0.0f, 1.0f, 0.0f); DrawQuad(); GL.PopMatrix(); GL.PushMatrix(); GL.Translate(1.0f, 0.0f, 0.0f); GL.Color3(0.0f, 0.0f, 1.0f); DrawQuad(); GL.PopMatrix(); _window.SwapBuffers(); pixels[0].ReadBuffer(99, 99); pixels[1].ReadBuffer(99, 100); pixels[2].ReadBuffer(100, 100); pixels[3].ReadBuffer(100, 99); _window.Close(); }; _window.Run(); Assert.AreEqual(new Pixel(1.0f, 1.0f, 1.0f), pixels[0]); Assert.AreEqual(new Pixel(1.0f, 0.0f, 0.0f), pixels[1]); Assert.AreEqual(new Pixel(0.0f, 1.0f, 0.0f), pixels[2]); Assert.AreEqual(new Pixel(0.0f, 0.0f, 1.0f), pixels[3]); }
public void TestOrtho() { var pixels = new[] {new Pixel(), new Pixel(), new Pixel(), new Pixel()}; _window = new GameWindow {Width = 200, Height = 200}; _window.RenderFrame += (caller, args) => { GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Ortho(0.0, 2.0, 0.0, 2.0, 0.0, 4.0); GL.Viewport(0, 0, 200, 200); GL.MatrixMode(MatrixMode.Modelview); GL.ReadBuffer(ReadBufferMode.Front); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Begin(PrimitiveType.Quads); { GL.Color3(1.0f, 1.0f, 1.0f); GL.Vertex2(0.0f, 0.0f); GL.Vertex2(1.0f, 0.0f); GL.Vertex2(1.0f, 1.0f); GL.Vertex2(0.0f, 1.0f); } GL.End(); _window.SwapBuffers(); pixels[0].ReadBuffer(99, 99); pixels[1].ReadBuffer(99, 100); pixels[2].ReadBuffer(100, 100); pixels[3].ReadBuffer(100, 99); _window.Close(); }; _window.Run(); Assert.AreEqual(new Pixel(1.0f, 1.0f, 1.0f), pixels[0]); Assert.AreEqual(new Pixel(0.0f, 0.0f, 0.0f), pixels[1]); Assert.AreEqual(new Pixel(0.0f, 0.0f, 0.0f), pixels[2]); Assert.AreEqual(new Pixel(0.0f, 0.0f, 0.0f), pixels[3]); }
private MyApplication() { //set waypoints of enemy wayPoints.Add(new Vector2(-.5f, -.5f)); wayPoints.Add(new Vector2(.5f, -.5f)); wayPoints.Add(new Vector2(.5f, .5f)); wayPoints.Add(new Vector2(-.5f, .5f)); //wayPoints.Add(new Vector2(.6f, -.7f)); //wayPoints.Add(new Vector2(.5f, .8f)); //wayPoints.Add(new Vector2(-.5f, .4f)); //wayPoints.Add(new Vector2(0, 0)); wayTangents = CatmullRomSpline.FiniteDifferenceLoop(wayPoints); //setup gameWindow = new GameWindow(700, 700); gameWindow.VSync = VSyncMode.On; gameWindow.KeyDown += (s, arg) => gameWindow.Close(); gameWindow.Resize += (s, arg) => GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height); gameWindow.UpdateFrame += GameWindow_UpdateFrame; gameWindow.RenderFrame += GameWindow_RenderFrame; gameWindow.RenderFrame += (s, arg) => gameWindow.SwapBuffers(); texBird = TextureLoader.FromBitmap(Resourcen.bird1); //background clear color GL.ClearColor(Color.White); //for transparency in textures GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); timeSource.Start(); }