Built-in effect that supports alpha testing.
Inheritance: Effect, IEffectMatrices, IEffectFog
Ejemplo n.º 1
0
        public ChunkModule(TrueCraftGame game)
        {
            Game = game;

            ChunkRenderer = new ChunkRenderer(Game.Client.World, Game, Game.BlockRepository);
            Game.Client.ChunkLoaded += Game_Client_ChunkLoaded;
            Game.Client.ChunkUnloaded += (sender, e) => UnloadChunk(e.Chunk);
            Game.Client.ChunkModified += Game_Client_ChunkModified;
            Game.Client.BlockChanged += Game_Client_BlockChanged;
            ChunkRenderer.MeshCompleted += MeshCompleted;
            ChunkRenderer.Start();
            WorldLighting = new WorldLighting(Game.Client.World.World, Game.BlockRepository);

            OpaqueEffect = new BasicEffect(Game.GraphicsDevice);
            OpaqueEffect.TextureEnabled = true;
            OpaqueEffect.Texture = Game.TextureMapper.GetTexture("terrain.png");
            OpaqueEffect.FogEnabled = true;
            OpaqueEffect.FogStart = 0;
            OpaqueEffect.FogEnd = Game.Camera.Frustum.Far.D * 0.8f;
            OpaqueEffect.VertexColorEnabled = true;
            OpaqueEffect.LightingEnabled = true;

            TransparentEffect = new AlphaTestEffect(Game.GraphicsDevice);
            TransparentEffect.AlphaFunction = CompareFunction.Greater;
            TransparentEffect.ReferenceAlpha = 127;
            TransparentEffect.Texture = Game.TextureMapper.GetTexture("terrain.png");
            TransparentEffect.VertexColorEnabled = true;
            OpaqueEffect.LightingEnabled = true;

            ChunkMeshes = new List<ChunkMesh>();
            IncomingChunks = new ConcurrentBag<Mesh>();
            ActiveMeshes = new HashSet<Coordinates2D>();
        }
Ejemplo n.º 2
0
 public Vehicle(string cfmFile)
 {
     _model = CarModelCache.GetCfm(cfmFile);
     _effect = new AlphaTestEffect(Engine.Instance.Device);
     Direction = Vector3.Forward;
     Up = Vector3.Up;
 }
Ejemplo n.º 3
0
        public ChunkModule(TrueCraftGame game)
        {
            Game = game;

            ChunkRenderer = new ChunkRenderer(Game.Client.World, Game, Game.BlockRepository);
            Game.Client.ChunkLoaded += (sender, e) => ChunkRenderer.Enqueue(e.Chunk);
            Game.Client.ChunkUnloaded += (sender, e) => UnloadChunk(e.Chunk);
            Game.Client.ChunkModified += (sender, e) => ChunkRenderer.Enqueue(e.Chunk, true);
            ChunkRenderer.MeshCompleted += MeshCompleted;
            ChunkRenderer.Start();

            OpaqueEffect = new BasicEffect(Game.GraphicsDevice);
            OpaqueEffect.TextureEnabled = true;
            OpaqueEffect.Texture = Game.TextureMapper.GetTexture("terrain.png");
            OpaqueEffect.FogEnabled = true;
            OpaqueEffect.FogStart = 512f;
            OpaqueEffect.FogEnd = 1000f;
            OpaqueEffect.FogColor = Color.CornflowerBlue.ToVector3();
            OpaqueEffect.VertexColorEnabled = true;

            TransparentEffect = new AlphaTestEffect(Game.GraphicsDevice);
            TransparentEffect.AlphaFunction = CompareFunction.Greater;
            TransparentEffect.ReferenceAlpha = 127;
            TransparentEffect.Texture = Game.TextureMapper.GetTexture("terrain.png");
            TransparentEffect.VertexColorEnabled = true;

            ChunkMeshes = new List<ChunkMesh>();
            IncomingChunks = new ConcurrentBag<Mesh>();
            ActiveMeshes = new HashSet<Coordinates2D>();
        }
Ejemplo n.º 4
0
        public Water(GraphicsDevice device, Texture2D particleTexture)
        {
            pb = new PrimitiveBatch(device);
            this.particleTexture = particleTexture;
            spriteBatch = new SpriteBatch(device);
            metaballTarget = new RenderTarget2D(device, device.Viewport.Width, device.Viewport.Height);
            particlesTarget = new RenderTarget2D(device, device.Viewport.Width, device.Viewport.Height);
            drawTarget = new RenderTarget2D(device, device.Viewport.Width, device.Viewport.Height);
            alphaTest = new AlphaTestEffect(device);
            alphaTest.ReferenceAlpha = 175;

            var view = device.Viewport;
            alphaTest.Projection = Matrix.CreateTranslation(-0.5f, -0.5f, 0) *
                Matrix.CreateOrthographicOffCenter(0, view.Width, view.Height, 0, 0, 1);

            for (int i = 0; i < columns.Length; i++)
            {
                columns[i] = new WaterColumn()
                {
                    Height = 240,
                    TargetHeight = 240,
                    Speed = 0
                };
            }
        }
Ejemplo n.º 5
0
        public RenderBatch(GraphicsDevice device, int primitivesPerBatch, bool enableAlphaBlend)
        {
            this.device = device;
            if (enableAlphaBlend)
            {
                BasicEffect be = new BasicEffect(device);
                Effect = be;
                fxMatrices = be;
                be.TextureEnabled = true;
                be.VertexColorEnabled = true;
                be.LightingEnabled = false;
                fxParamTexture = Effect.Parameters["Texture"];
            }
            else
            {
                AlphaTestEffect ate = new AlphaTestEffect(device);
                Effect = ate;
                fxMatrices = ate;
                ate.VertexColorEnabled = true;
                ate.ReferenceAlpha = 128;
                fxParamTexture = Effect.Parameters["Texture"];
            }

            this.maxPrimitivesPerBatch = primitivesPerBatch;
        }
 /// <summary>
 /// Initializes this instance.
 /// </summary>
 /// <param name="ginfo"></param>
 /// <param name="factory"></param>
 /// <param name="obj"></param>
 public override void Initialize(GraphicInfo ginfo, GraphicFactory factory, IObject obj)
 {
     effect = factory.GetAlphaTestEffect();
     effect.ReferenceAlpha = alphaToCut;
     effect.AlphaFunction = CompareFunction;
     base.Initialize(ginfo,factory,obj);            
 }
Ejemplo n.º 7
0
        public void Render(GraphicsDevice device, Camera camera, SpriteBatch spriteBatch, AlphaTestEffect textEffect)
        {
            Matrix bill = Matrix.CreateBillboard(_position, camera.Position, Vector3.Down, camera.Direction);
            //Matrix bill = Matrix.CreateConstrainedBillboard(_position, camera.Position, Vector3.Down, camera.Direction,
            //                                    Vector3.Forward);
            float xOffset = _font.MeasureString(_text).X/2;

            textEffect.World = bill;
            textEffect.View = camera.View;
            textEffect.Projection = camera.Projection;
            textEffect.AlphaFunction = CompareFunction.Greater;
            textEffect.ReferenceAlpha = 128;
            textEffect.VertexColorEnabled = true;

            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.PointClamp, DepthStencilState.DepthRead,
                                  RasterizerState.CullNone, textEffect);
            for (int x = -_outlineSize; x <= _outlineSize; x++)
            {
                for (int y = -_outlineSize; y <= _outlineSize; y++)
                {
                    if (x == 0 && y == 0) continue;

                    spriteBatch.DrawString(_font, _text, new Vector2(-xOffset + x, y), _outlineColor);
                }
            }

            spriteBatch.DrawString(_font, _text, new Vector2(-xOffset, 0), _textColor);

            spriteBatch.End();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a simple shader to render 3D meshes using the BasicEffect class.
        /// </summary>
        /// <exception cref="GoblinException"></exception>
        public AlphaTestShader()
        {
            if (!State.Initialized)
                throw new GoblinException("Goblin XNA needs to be initialized first using State.InitGoblin(..)");

            alphaEffect = new AlphaTestEffect(State.Device);
        }
Ejemplo n.º 9
0
        public WaterBase(Vector3 origin, float height, Vector2 size, String baseTextureKey, String waveTextureKey, int xRowTextures, int yRowTextures, string effectKey, int waveDensity, Game1 game)
            : base(game)
        {
            this.game = game;
            this.origin = origin;
            this.size = size;
            this.baseTextureKey = baseTextureKey;
            this.waveTextureKey = waveTextureKey;
            this.xRowTextures = xRowTextures;
            this.yRowTextures = yRowTextures;
            this.graphicsDevice = game.GraphicsDevice;
            this.content = game.Content;
            this.effectKey = effectKey;
            this.waveDensity = waveDensity;

            vertices = new VertexPositionNormalTexture[4];

            camera = (Camera.Camera)game.Services.GetService(typeof(Camera.Camera));
            level = (States.Level)game.Services.GetService(typeof(States.Level));

            baseEffect = new AlphaTestEffect(graphicsDevice);

            randy = new Random();

            LoadContent();

            //Calculates were the corner vectors of the quad are qoing to be
            CalcVertices();
            FillVertices();
            LoadWaves();
        }
Ejemplo n.º 10
0
 public Track()
 {
     _effect = new AlphaTestEffect(Engine.Instance.Device);
     _effect.ReferenceAlpha = 100;
     _effect.AlphaFunction = CompareFunction.Greater;
     _effect.VertexColorEnabled = false;
     _effect.FogEnabled = false;
     _physicalRoadEffect = new BasicEffect(Engine.Instance.Device);
 }
Ejemplo n.º 11
0
 public Pinkie(Game game)
     : base(game)
 {
     alphaTestEffect = new AlphaTestEffect(device);
     basicEffect = new BasicEffect(device);
     pinkie = game.Content.Load<Texture2D>("pinkie");
     party = game.Content.Load<Texture2D>("party");
     CreateGeometry();
 }
Ejemplo n.º 12
0
        public HighlightModule(TrueCraftGame game)
        {
            Game = game;
            HighlightEffect = new BasicEffect(Game.GraphicsDevice);
            HighlightEffect.VertexColorEnabled = true;
            DestructionEffect = new AlphaTestEffect(Game.GraphicsDevice);
            DestructionEffect.Texture = game.TextureMapper.GetTexture("terrain.png");
            DestructionEffect.ReferenceAlpha = 1;

            GenerateProgressMesh();
        }
Ejemplo n.º 13
0
    public SpriteRenderer(GraphicsDeviceManager graphics, ContentManager content)
    {
        this.graphics = graphics;
        this.content = content;

        quadEffect = new AlphaTestEffect(graphics.GraphicsDevice);

        quadEffect.World = Camera.main.world;
        quadEffect.View = Camera.main.view;
        quadEffect.Projection = Camera.main.projection;
    }
Ejemplo n.º 14
0
        public void BeginScene(BasicEffect effect, AlphaTestEffect spriteEffect, GraphicsDevice device)
        {
            this.effect = effect;
            this.device = device;
            this.spriteEffect = spriteEffect;

            if (White == null)
            {
                White = new Texture2D(device, 1, 1, false, SurfaceFormat.Color);
                White.SetData(new Color[] { new Color(255, 255, 255, 255) });
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Loads content for this demo.
        /// </summary>
        protected override void LoadContent()
        {
            tank.Load(Game.Content);

            renderTarget = new RenderTarget2D(GraphicsDevice, 400, 400, false, SurfaceFormat.Color, DepthFormat.Depth24);

            alphaTestEffect = new AlphaTestEffect(GraphicsDevice);
            alphaTestEffect.AlphaFunction = CompareFunction.Greater;
            alphaTestEffect.ReferenceAlpha = 128;

            grid = Game.Content.Load<Model>("grid");
        }
Ejemplo n.º 16
0
 public Twilight(Game game)
     : base(game)
 {
     basicEffect = new BasicEffect(device);
     alphaTestEffect = new AlphaTestEffect(device);
     chessboard = game.Content.Load<Texture2D>("chessboard");
     books = game.Content.Load<Texture2D>("books");
     twilight = game.Content.Load<Texture2D>("twilight");
     spike = game.Content.Load<Texture2D>("spike");
     scroll = game.Content.Load<Texture2D>("scroll");
     CreateGeometry();
 }
 public MultipassSimpleEffectRenderer_SingleChannel(GraphicsDevice device)
 {
     _device = device;
     _basicEffect = new BasicEffect(_device)
     {
         LightingEnabled = false,
         VertexColorEnabled = true,
         TextureEnabled = true
     };
     _alphaTestEffect = new AlphaTestEffect(_device)
     {
         VertexColorEnabled = true
     };
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Constructs a new quadrilateral drawing worker.
        /// </summary>
        public QuadDrawer(GraphicsDevice device)
        {
            graphicsDevice = device;

            effect = new AlphaTestEffect(device);

            effect.AlphaFunction = CompareFunction.Greater;
            effect.ReferenceAlpha = 128;

            // Preallocate an array of four vertices.
            vertices = new VertexPositionTexture[4];

            vertices[0].Position = new Vector3(1, 1, 0);
            vertices[1].Position = new Vector3(-1, 1, 0);
            vertices[2].Position = new Vector3(1, -1, 0);
            vertices[3].Position = new Vector3(-1, -1, 0);
        }
Ejemplo n.º 19
0
        public Horizontal(Vector3 origin, Vector2 size, float height, Texture2D texture, int xRowTextures, int yRowTextures, GraphicsDevice graphicsDevice, ContentManager content)
        {
            vertices = new VertexPositionNormalTexture[4];

            this.height = height;
            this.origin = origin;
            this.size = size;
            //this.waterTexture = texture;
            this.xRowTextures = xRowTextures;
            this.yRowTextures = yRowTextures;
            this.graphicsDevice = graphicsDevice;

            effect = new AlphaTestEffect(graphicsDevice);

            //Calculates were the corner vectors of the quad are qoing to be
            CalcVertices();

            FillVertices();
        }
Ejemplo n.º 20
0
        public Renderer(GraphicsDevice device, ContentManager content)
        {
            this.device = device;
            debug = new ImmediateModeDebug(device);

            drawEffect = new BasicEffect(device);
            drawEffect.TextureEnabled = true;
            drawEffect.VertexColorEnabled = false;

            drawSpriteEffect = new AlphaTestEffect(device);
            drawSpriteEffect.VertexColorEnabled = false;

            drawIDEffect = new BasicEffect(device);
            drawIDEffect.TextureEnabled = false;
            drawIDEffect.VertexColorEnabled = false;

            Camera.Viewport = device.Viewport;

            mousePickTarget = new RenderTarget2D(device, 1, 1, false, SurfaceFormat.Color, DepthFormat.Depth24);

            immediate2d = new ImmediateMode2d(device);
        }
Ejemplo n.º 21
0
        public Renderer(Manager manager)
        {
            // Cache of gradients.
            gradientCache = new Dictionary<GradientBrush, Texture2D>();
            stencilAreas = new List<Rectangle>();
            this.manager = manager;
            graphics = manager.SpriteBatch.GraphicsDevice;

            // Create stencils for drawing masked sprites.
            var matrix = Matrix.CreateOrthographicOffCenter(0,
                graphics.PresentationParameters.BackBufferWidth,
                graphics.PresentationParameters.BackBufferHeight,
                0, 0, 1
                );
            alphaTextEffect = new AlphaTestEffect(graphics)
            {
                Projection = matrix
            };
            maskStencil = new DepthStencilState
            {
                StencilEnable = true,
                StencilFunction = CompareFunction.Always,
                StencilPass = StencilOperation.Replace,
                ReferenceStencil = 1,
                DepthBufferEnable = false,
            };
            renderStencil = new DepthStencilState
            {
                StencilEnable = true,
                StencilFunction = CompareFunction.LessEqual,
                StencilPass = StencilOperation.Keep,
                ReferenceStencil = 1,
                DepthBufferEnable = false,
            };

            // Create 1x1 texture for rendering rectangles.
            pixel = new Texture2D(manager.SpriteBatch.GraphicsDevice, 1, 1);
            pixel.SetData(new[] {ColorXNA.White});
        }
Ejemplo n.º 22
0
		public BlendableSprite(GameObject parent, SpriteBase sprite, Color color)
			: base(parent)
		{
			_Sprite = sprite;

			Width = _Sprite.Width;
			Height = _Sprite.Height;
			Size = _Sprite.Size;

			_BlendTexture = new Texture2D(GameCore.GraphicsDevice, 1, 1);
			_BlendTexture.SetData(new[] { color });

			_AlphaTestEffect = new AlphaTestEffect(GameCore.GraphicsDevice)
			{
				DiffuseColor = Color.White.ToVector3(),
				AlphaFunction = CompareFunction.Greater,
				ReferenceAlpha = 0,
				World = Matrix.Identity,
				View = Matrix.Identity,
				Projection = Matrix.CreateTranslation(-0.5f, -0.5f, 0) *
					Matrix.CreateOrthographicOffCenter(0, GameCore.GraphicsDevice.Viewport.Width, GameCore.GraphicsDevice.Viewport.Height, 0, 0, 1)
			};
		}
Ejemplo n.º 23
0
        public HorizontalBillboarding(Vector3 origin, float height, Vector2 size, Texture2D texture, int xRowTextures, int yRowTextures, GraphicsDevice graphicsDevice, ContentManager content, Game game)
            : base(game)
        {
            this.origin = origin;
            this.size = size;
            this.texture = texture;
            this.xRowTextures = xRowTextures;
            this.yRowTextures = yRowTextures;
            this.graphicsDevice = graphicsDevice;
            this.content = content;
            this.game = game;

            vertices = new VertexPositionNormalTexture[4];

            camera = (Camera.Camera)game.Services.GetService(typeof(Camera.Camera));
            level = (States.Level)game.Services.GetService(typeof(States.Level));

            effect = new AlphaTestEffect(graphicsDevice);

            //Calculates were the corner vectors of the quad are qoing to be
            CalcVertices();

            FillVertices();
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Creates a new AlphaTestEffect by cloning parameter settings from an existing instance.
        /// </summary>
        protected AlphaTestEffect(AlphaTestEffect cloneSource)
            : base(cloneSource)
        {
            CacheEffectParameters();

            fogEnabled = cloneSource.fogEnabled;
            vertexColorEnabled = cloneSource.vertexColorEnabled;

            world = cloneSource.world;
            view = cloneSource.view;
            projection = cloneSource.projection;

            diffuseColor = cloneSource.diffuseColor;

            alpha = cloneSource.alpha;

            fogStart = cloneSource.fogStart;
            fogEnd = cloneSource.fogEnd;
            
            alphaFunction = cloneSource.alphaFunction;
            referenceAlpha = cloneSource.referenceAlpha;

        }
Ejemplo n.º 25
0
        protected override void LoadContent()
        {
            // Ensure we have default textures loaded.
            TextureMapper.LoadDefaults(GraphicsDevice);

            // Load any custom textures if needed.
            TextureMapper = new TextureMapper(GraphicsDevice);
            if (UserSettings.Local.SelectedTexturePack != TexturePack.Default.Name)
                TextureMapper.AddTexturePack(TexturePack.FromArchive(Path.Combine(TexturePack.TexturePackPath, UserSettings.Local.SelectedTexturePack)));

            Pixel = new FontRenderer(
                new Font(Content, "Fonts/Pixel", FontStyle.Regular),
                new Font(Content, "Fonts/Pixel", FontStyle.Bold),
                null, // No support for underlined or strikethrough yet. The FontRenderer will revert to using the regular font style.
                null, // (I don't think BMFont has those options?)
                new Font(Content, "Fonts/Pixel", FontStyle.Italic));
            Interfaces.Add(ChatInterface = new ChatInterface(Client, KeyboardComponent, Pixel));
            Interfaces.Add(DebugInterface = new DebugInterface(Client, Pixel));

            ChatInterface.IsVisible = true;
            DebugInterface.IsVisible = true;

            OpaqueEffect = new BasicEffect(GraphicsDevice);
            OpaqueEffect.EnableDefaultLighting();
            OpaqueEffect.DirectionalLight0.SpecularColor = Color.Black.ToVector3();
            OpaqueEffect.DirectionalLight1.SpecularColor = Color.Black.ToVector3();
            OpaqueEffect.DirectionalLight2.SpecularColor = Color.Black.ToVector3();
            OpaqueEffect.TextureEnabled = true;
            OpaqueEffect.Texture = TextureMapper.GetTexture("terrain.png");
            OpaqueEffect.FogEnabled = true;
            OpaqueEffect.FogStart = 512f;
            OpaqueEffect.FogEnd = 1000f;
            OpaqueEffect.FogColor = Color.CornflowerBlue.ToVector3();
            OpaqueEffect.VertexColorEnabled = true;

            TransparentEffect = new AlphaTestEffect(GraphicsDevice);
            TransparentEffect.AlphaFunction = CompareFunction.Greater;
            TransparentEffect.ReferenceAlpha = 127;
            TransparentEffect.Texture = TextureMapper.GetTexture("terrain.png");
            TransparentEffect.VertexColorEnabled = true;

            base.LoadContent();
        }
Ejemplo n.º 26
0
        public override void Visit()
        {
            if (m_pStencil == null || !m_pStencil.Visible)
            {
                if (m_bInverted)
                {
                    // draw everything
                    base.Visit();
                }
                return;
            }

            if (_layer + 1 == 8) //DepthFormat.Depth24Stencil8
            {
                if (_once)
                {
                    CCLog.Log(
                        "Nesting more than 8 stencils is not supported. Everything will be drawn without stencil for this node and its childs."
                        );
                    _once = false;
                }
                base.Visit();
                return;
            }

            _layer++;

            int maskLayer = 1 << _layer;
            int maskLayerL = maskLayer - 1;
            int maskLayerLe = maskLayer | maskLayerL;

            var saveDepthStencilState = CCDrawManager.DepthStencilState;

            ///////////////////////////////////
            // CLEAR STENCIL BUFFER

            var stencilState = new DepthStencilState()
                {
                    DepthBufferEnable = false,

                    StencilEnable = true,
                    
                    StencilFunction = CompareFunction.Never,

                    StencilMask = maskLayer,
                    StencilWriteMask = maskLayer,
                    ReferenceStencil = maskLayer,

                    StencilFail = !m_bInverted ? StencilOperation.Zero : StencilOperation.Replace
                };
            CCDrawManager.DepthStencilState = stencilState;

            // draw a fullscreen solid rectangle to clear the stencil buffer
            var size = CCDirector.SharedDirector.WinSize;

            CCDrawManager.PushMatrix();
            CCDrawManager.SetIdentityMatrix();

            CCDrawingPrimitives.Begin();
            CCDrawingPrimitives.DrawSolidRect(CCPoint.Zero, new CCPoint(size.Width, size.Height), new CCColor4B(255, 255, 255, 255));
            CCDrawingPrimitives.End();

            CCDrawManager.PopMatrix();
            
            ///////////////////////////////////
            // DRAW CLIPPING STENCIL

            stencilState = new DepthStencilState()
                {
                    DepthBufferEnable = false,

                    StencilEnable = true,

                    StencilFunction = CompareFunction.Never,

                    StencilMask = maskLayer,
                    StencilWriteMask = maskLayer,
                    ReferenceStencil = maskLayer,

                    StencilFail = !m_bInverted ? StencilOperation.Replace : StencilOperation.Zero,
                };
            CCDrawManager.DepthStencilState = stencilState;
            
            if (m_fAlphaThreshold < 1)
            {
                if (_alphaTest == null)
                {
                    _alphaTest = new AlphaTestEffect(CCDrawManager.GraphicsDevice);
                    _alphaTest.AlphaFunction = CompareFunction.Greater;
                }

                _alphaTest.ReferenceAlpha = (byte)(255 * m_fAlphaThreshold);

                CCDrawManager.PushEffect(_alphaTest);
            }

            CCDrawManager.PushMatrix();
            Transform();
            m_pStencil.Visit();
            CCDrawManager.PopMatrix();

            if (m_fAlphaThreshold < 1)
            {
                CCDrawManager.PopEffect();
            }

            ///////////////////////////////////
            // DRAW CONTENT

            stencilState = new DepthStencilState()
            {
                DepthBufferEnable = saveDepthStencilState.DepthBufferEnable,

                StencilEnable = true,
                
                StencilMask = maskLayerLe,
                StencilWriteMask = 0,
                ReferenceStencil = maskLayerLe,

                StencilFunction = CompareFunction.Equal,

                StencilPass = StencilOperation.Keep,
                StencilFail = StencilOperation.Keep,
            };
            CCDrawManager.DepthStencilState = stencilState;
            
            
            base.Visit();

            //Restore DepthStencilState
            CCDrawManager.DepthStencilState = saveDepthStencilState;

            _layer--;
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Loads graphics content for this screen. The background texture is quite
        /// big, so we use our own local ContentManager to load it. This allows us
        /// to unload before going from the menus into the game itself, wheras if we
        /// used the shared ContentManager provided by the Game class, the content
        /// would remain loaded forever.
        /// </summary>
        public override void LoadContent()
        {
            if (content == null)
                content = new ContentManager(ScreenManager.Game.Services, "Psuedo3DRacer.Content");

            LoadTex("arrow");
            LoadTex("blank");
            LoadTex("blank-track");
            LoadTex("banner-bottom");
            LoadTex("banner-top");
            LoadTex("car-spot");
            LoadTex("colors");
            LoadTex("paintcar");
            LoadTex("selectcup");
            LoadTex("triangles");
            LoadTex("cup-holder");
            LoadTex("cuparrow");
            LoadTex("cup");

            for (int i = 1; i <= 3; i++)
            {
                LoadTex("cuptitle" + i.ToString());
            }

            texCarDirections = new Texture2D[8];
            for (int dir = 0; dir < 8; dir++)
            {
                texCarDirections[dir] = content.Load<Texture2D>("cars/0-" + dir + "-0");
            }

            Parallax = new ParallaxManager(ScreenManager.Viewport);
            Camera = new Camera(ScreenManager.GraphicsDevice, ScreenManager.Viewport);
            Track = Track.Load("track000", content, Parallax, false);

            drawEffect = new BasicEffect(ScreenManager.GraphicsDevice)
            {
                World = Camera.worldMatrix,
                View = Camera.viewMatrix,
                Projection = Camera.projectionMatrix,
                TextureEnabled = true
            };

            drawAlphaEffect = new AlphaTestEffect(ScreenManager.GraphicsDevice)
            {
                World = Camera.worldMatrix,
                View = Camera.viewMatrix,
                Projection = Camera.projectionMatrix,
                ReferenceAlpha = 254,
                AlphaFunction = CompareFunction.Greater
            };

            // Initial positions
            bannerTop1Pos = new Vector2(150, -230);
            bannerTop2Pos = new Vector2(400, -230);

            CarPos = new Vector2(ScreenManager.Viewport.Width / 2, -250f);
            SpotPos = new Vector2(ScreenManager.Viewport.Width / 2, ScreenManager.Viewport.Height + 500f);
            PaintPos = new Vector2(ScreenManager.Viewport.Width / 2, ScreenManager.Viewport.Height + 500f);

            Cups.Add(new Cup());
            Cups.Add(new Cup());
            Cups.Add(new Cup());
            //Cups.Add(new Cup());
            //Cups.Add(new Cup());

            cupPosition = new Vector2(ScreenManager.Viewport.Width + 500, ScreenManager.Viewport.Height / 2);
            for (int i = selectedCup - 2; i <= selectedCup + 2; i++)
            {
                if (i >= 0 && i < Cups.Count)
                {
                    Cups[i].Position = cupPosition + new Vector2(i * 150, 0);
                    Cups[i].Scale = 1f - (Math.Abs(i) * 0.25f);
                }
            }

            cupTrackRT[0] = new RenderTarget2D(ScreenManager.GraphicsDevice, 193, 108, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8);
            cupTrackRT[1] = new RenderTarget2D(ScreenManager.GraphicsDevice, 193, 108, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8);
            cupTrackRT[2] = new RenderTarget2D(ScreenManager.GraphicsDevice, 193, 108, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8);

            trophyPos = new Vector2(- 400, (ScreenManager.Viewport.Height / 2) + 50);

            leftRect = new Rectangle(0, ScreenManager.Viewport.Height - 75, 150, 50);
            rightRect = new Rectangle(ScreenManager.Viewport.Width-150, ScreenManager.Viewport.Height - 75, 150, 50);

            leftCupRect = new Rectangle((int)cupPosition.X - 300, (int)cupPosition.Y - 100, 50, 200);
            rightCupRect = new Rectangle((int)cupPosition.X + 250, (int)cupPosition.Y - 100, 50, 200);

            LoadTracks(selectedCup);
            AudioController.PlayMusic("title");
            ScreenManager.Game.ResetElapsedTime();
        }
        /// <summary>
        /// Prepare a BasicEffect for rendering
        /// </summary>
        /// <param name="effect"></param>
        protected void PrepareEffect(AlphaTestEffect effect)
        {
            if (effect.Texture != ObjectTexture) effect.Texture = ObjectTexture;

            // Set the color and alpha
            effect.DiffuseColor = ObjectColor.ToVector3();
            effect.Alpha = (float)ObjectColor.A / 255.0f;

            // Apply the transformation matrix
            effect.World = Transformation;

            // Now the effect is ready for the derived class to actually draw the object
        }
Ejemplo n.º 29
0
        public void Pop()
        {
            if (states.Count == 0)
                return;
            if (IsDrawing)
                End();

            var s = states[states.Count - 1];
            states.RemoveAt(states.Count - 1);

            s1 = s.s1;
            s2 = s.s2;
            a = s.a;

            Overlay = s.Overlay;

            if (s.IsDrawing)
            {
                if (s.MaskBeingUsed)
                {
                    if (s.IsScaled)
                        MaskUseScaled();
                    else
                        MaskUse();
                }
                else
                {
                    if (s.MaskBeingDrawnOn)
                    {
                        if (s.IsScaled)
                            MaskBeginDrawOnScaled();
                        else
                            MaskBeginDrawOn();
                    }
                    else
                        if (s.FBO != null)
                            EnableFBO(s.FBO);
                    Begin(s.IsScaled);
                }
            }
        }
Ejemplo n.º 30
0
Archivo: Mask.cs Proyecto: hgrandry/Mgx
        private void Setup()
        {
            if (_spriteBatch != null)
                _spriteBatch.Dispose();

            _spriteBatch = new SpriteBatch(Render.Device);

            _alphaTestEffect = new AlphaTestEffect(Render.Device)
            {
                Projection = Matrix.CreateOrthographicOffCenter(0, Render.Viewport.Width, Render.Viewport.Height, 0, 0, 1),
                DiffuseColor = Color.Black.ToVector3()
            };
        }