public SfmlVideo(Config config, GameContent content, RenderWindow window) { try { Console.Write("Initialize video: "); renderer = new Renderer(config, content); config.video_gamescreensize = Math.Clamp(config.video_gamescreensize, 0, MaxWindowSize); config.video_gammacorrection = Math.Clamp(config.video_gammacorrection, 0, MaxGammaCorrectionLevel); this.window = window; windowWidth = (int)window.Size.X; windowHeight = (int)window.Size.Y; if (config.video_highresolution) { textureWidth = 512; textureHeight = 1024; } else { textureWidth = 256; textureHeight = 512; } textureData = new byte[4 * renderer.Width * renderer.Height]; texture = new global::SFML.Graphics.Texture((uint)textureWidth, (uint)textureHeight); sprite = new global::SFML.Graphics.Sprite(texture); sprite.Position = new Vector2f(0, 0); sprite.Rotation = 90; var scaleX = (float)windowWidth / renderer.Width; var scaleY = (float)windowHeight / renderer.Height; sprite.Scale = new Vector2f(scaleY, -scaleX); sprite.TextureRect = new IntRect(0, 0, renderer.Height, renderer.Width); renderStates = new RenderStates(BlendMode.None); Console.WriteLine("OK"); } catch (Exception e) { Console.WriteLine("Failed"); Dispose(); ExceptionDispatchInfo.Throw(e); } }
public void Dispose() { Console.WriteLine("Shutdown renderer."); if (sprite != null) { sprite.Dispose(); sprite = null; } if (texture != null) { texture.Dispose(); texture = null; } }