public static void Run() { Window window = new Window(1024, 768, "GetPixels"); RenderTexture screen = new RenderTexture(800, 600); Sprite sprite = new Sprite(100, 100); // half the render texture (to retain aspect ratio) Sprite lowAngle = new Sprite(400, 300); Sprite final = new Sprite(800, 600); GrayscaleEffect effect = new GrayscaleEffect(); YellowizerEffect yellowizer = new YellowizerEffect(); sprite.position = new Vector2(200, 200); lowAngle.position = new Vector2(400, 400); Random random = new Random(); Texture dumbTexture = new Texture(800, 600); // in opengl, textures are flipped on the y axis dumbTexture.flipped = true; Masker masker = new Masker(); masker.AddTexture("mask", new Texture("RenderTexture/Assets/star.png")); window.AddPostProcessingEffect(masker); window.SetClearColor(0, 0, 255, 255); while (window.IsOpened) { sprite.EulerRotation += 30 * window.DeltaTime; window.RenderTo(screen); sprite.DrawColor(255, 0, 0); if (random.Next() % 2 == 0) { screen.ApplyPostProcessingEffect(effect); } if (random.Next() % 2 == 0) { screen.ApplyPostProcessingEffect(yellowizer); } window.RenderTo(null); final.DrawRenderTexture(screen); byte[] data = screen.Download(); dumbTexture.Update(data); lowAngle.DrawTexture(dumbTexture); GC.Collect(); window.Update(); } }
private static void FullExample() { Window Win = new Window(1280, 720, "RenderTV"); Texture bgTexture = new Texture("RenderTV/Assets/vaporBg.jpg"); Sprite bg = new Sprite(bgTexture.Width, bgTexture.Height); Texture shipTexture = new Texture("RenderTV/Assets/futurama_ship.png"); Sprite ship = new Sprite(shipTexture.Width, shipTexture.Height); ship.position = new Vector2(300, 300); RenderTexture renderT = new RenderTexture(Win.Width, Win.Height); Sprite renderSprite = new Sprite(Win.Width * 0.4f, Win.Height * 0.4f); renderSprite.pivot = new Vector2(renderSprite.Width * 0.5f, renderSprite.Height * 0.5f); renderSprite.position = new Vector2(Win.Width * 0.5f, Win.Height * 0.5f); Texture tvTexture = new Texture("RenderTV/Assets/tv.png"); Sprite tv = new Sprite(tvTexture.Width, tvTexture.Height); tv.pivot = new Vector2(tv.Width * 0.5f, tv.Height * 0.5f); tv.position = renderSprite.position; tv.scale = new Vector2(0.4f, 0.4f); float accumulator = 0; WobbleFX wobble = new WobbleFX(2); GrayScaleFX grayScale = new GrayScaleFX(); while (Win.IsOpened) { //Update accumulator += Win.DeltaTime * 2; ship.position.Y -= (float)Math.Sin(accumulator) * 50 * Win.DeltaTime; wobble.Update(Win); //Draw Win.RenderTo(renderT); bg.DrawTexture(bgTexture); ship.DrawTexture(shipTexture); renderT.ApplyPostProcessingEffect(wobble); renderT.ApplyPostProcessingEffect(grayScale); Win.RenderTo(null); renderSprite.DrawRenderTexture(renderT); tv.DrawTexture(tvTexture); Win.Update(); } }