コード例 #1
0
ファイル: Renderer.cs プロジェクト: cadahl/defense
        public Renderer()
        {
            int sw = 1024;
            int sh = 768;

            Window = new GameWindow(sw,sh,OpenTK.Graphics.GraphicsMode.Default,"Client",GameWindowFlags.Default,DisplayDevice.Default, 2, 1, OpenTK.Graphics.GraphicsContextFlags.Default);

            //Window.VSync = VSyncMode.On;
            Window.UpdateFrame += HandleWindowUpdateFrame;
            Window.RenderFrame += HandleWindowRenderFrame;

            Tilemaps = new Dictionary<string, Tilemap> ();
            Backgrounds = new Dictionary<int, Background> ();
            ShaderCache = new Dictionary<int, int>();
            Materials = new Dictionary<string, Material>();
            _drawList = new List<Drawable> ();

            _vb = new VertexBuffer();

            GL.ShadeModel (ShadingModel.Smooth);
            GL.Disable (EnableCap.CullFace);
            GL.Enable (EnableCap.Texture2D);
            GL.Disable (EnableCap.DepthTest);
            GL.DepthMask(false);
            GL.Enable (EnableCap.Blend);
            GL.BlendFunc (BlendingFactorSrc.One, BlendingFactorDest.OneMinusSrcAlpha);
            //GL.Enable (EnableCap.LineSmooth);
            //GL.Hint (HintTarget.LineSmoothHint, HintMode.Nicest);
            GL.PixelStore (PixelStoreParameter.UnpackAlignment, 1);
            GL.ClearColor (0.3f, 0.3f, 0.3f, 1f);
            GL.CullFace (CullFaceMode.Back);
            GL.Disable(EnableCap.AlphaTest);

            _rtt = new RenderToTexture(Width, Height);
            _compositingMaterial = GetMaterial("distort");

            ZoomLevel = 1.0f;

            Window.Resize += (sender, e) =>
            {
                GL.Viewport (0, 0, Window.ClientSize.Width, Window.ClientSize.Height);
                GL.MatrixMode (MatrixMode.Projection);
                GL.LoadIdentity ();
                GL.Ortho (0, Window.ClientSize.Width*ZoomLevel, Window.ClientSize.Height*ZoomLevel, 0, -100.0, 100.0);
            };

            Window.Unload += (sender, e) =>
            {
                var textures = (from t in Tilemaps.Values select t.Texture).ToArray();
                GL.DeleteTextures(textures.Length, textures);

                foreach(var m in Materials.Values)
                    m.Dispose();

                _rtt.Dispose();
                _compositingMaterial.Dispose();
            };
        }