/// <summary> /// Helper for setting the renderstates used to draw particles. /// </summary> void SetParticleRenderStates(GraphicsDevice device) { // Enable point sprites. PointSpriteHelper.Enable(); // renderState.PointSizeMax = 256; // FIXME: Do we care? -flibit // Set the alpha blend mode. BlendStateHelper.BeginApply(device); BlendStateHelper.AlphaBlendEnable = true; BlendStateHelper.SourceBlend = settings.SourceBlend; BlendStateHelper.DestinationBlend = settings.DestinationBlend; BlendStateHelper.EndApply(device); // Enable the depth buffer (so particles will not be visible through // solid objects like the ground plane), but disable depth writes // (so particles will not obscure other particles). device.DepthStencilState = DepthStencilState.DepthRead; }
public void Draw(GameTime gameTime, Camera camera) { try { // First, we need to figure out which stars // are behind us and throw them out in front of us again // based on how fast the camera is moving if (!motionReady) { GenerateStars(camera); vertexBuffer.SetData <VertexPointSprite>(data); } else { MoveStars(camera); vertexBuffer.SetData <VertexPointSprite>(data); } { // // STARS // starEffect.Parameters["World"].SetValue(Matrix.Identity); starEffect.Parameters["View"].SetValue(camera.View); starEffect.Parameters["Projection"].SetValue(camera.Projection); starEffect.Parameters["Texture"].SetValue(starTexture); starEffect.Parameters["ViewportHeight"].SetValue(GraphicsDevice.Viewport.Height); GraphicsDevice.SetVertexBuffer(vertexBuffer); PointSpriteHelper.Enable(); // Set the alpha blend mode. BlendStateHelper.BeginApply(GraphicsDevice); BlendStateHelper.AlphaBlendEnable = true; BlendStateHelper.SourceBlend = Blend.SourceAlpha; BlendStateHelper.DestinationBlend = Blend.InverseSourceAlpha; BlendStateHelper.EndApply(GraphicsDevice); // Enable the depth buffer (so particles will not be visible through // solid objects like the space ship), but disable depth writes // (so particles will not obscure other particles). GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead; for (int i = 0; i < starEffect.CurrentTechnique.Passes.Count; ++i) { starEffect.CurrentTechnique.Passes[i].Apply(); #if SDL2 GraphicsDevice.DrawPrimitives(PrimitiveType.PointListEXT, 0, starCount); #endif } PointSpriteHelper.Disable(); GraphicsDevice.SetVertexBuffer(null); BlendStateHelper.BeginApply(GraphicsDevice); BlendStateHelper.AlphaBlendEnable = false; BlendStateHelper.EndApply(GraphicsDevice); if (GraphicsDevice.DepthStencilState.DepthBufferEnable) { GraphicsDevice.DepthStencilState = DepthStencilState.Default; } else { GraphicsDevice.DepthStencilState = Helpers.DepthWrite; } } base.Draw(gameTime); } catch { } }