public override void Draw(GameTime gameTime) { //BasicEffect effect = new BasicEffect(GraphicsDevice, null); effect.World = Matrix.Identity; //No transformation of the terrain effect.View = Game1.camera.view; effect.Projection = Game1.camera.project; effect.Texture = texture; effect.TextureEnabled = true; GraphicsDevice.Vertices[0].SetSource(vb, 0, VertexPositionTexture.SizeInBytes); //Set vertices GraphicsDevice.Indices = ib; //Set indices GraphicsDevice.VertexDeclaration = new VertexDeclaration(GraphicsDevice, VertexPositionTexture.VertexElements); //Decalre type of vertices effect.Begin(); //Begin effect foreach (EffectPass CurrentPass in effect.CurrentTechnique.Passes) { CurrentPass.Begin(); GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, numVertices, 0, numTriangles); //Draw all triangles that make up the mesh CurrentPass.End(); } effect.End(); base.Draw(gameTime); }
public void Draw(GameTime gameTime, Camera camera) { float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; effect.Parameters["view"].SetValue(camera.View); effect.Parameters["projection"].SetValue(camera.Projection); effect.Parameters["viewportHeight"].SetValue(device.Viewport.Height); effect.Parameters["modelTexture"].SetValue(texture); spriteArray_Count = -1; for (int i = 0; i < particle.Length; i++) { if (particle[i].isActive) { spriteArray[++spriteArray_Count] = new VertexPointSprite(particle[i].position, particle[i].Scale * PointSize, particle[i].ParColor); } } if (spriteArray_Count <= 0) { return; } // 頂點格式宣告 device.VertexDeclaration = pointSpriteVertexDeclaration; SetParticleRenderStates(device.RenderState); /* * device.RenderState.AlphaBlendEnable = true; * device.RenderState.SourceBlend = Blend.SourceAlpha; * device.RenderState.DestinationBlend = Blend.InverseSourceAlpha; * device.RenderState.AlphaTestEnable = true; * device.RenderState.AlphaFunction = CompareFunction.Greater; * device.RenderState.PointSize = 1000.0f; * device.RenderState.PointSizeMax = 10000.0f; * device.RenderState.PointSizeMin = 100.0f; * device.RenderState.DepthBufferEnable = true ; */ effect.CurrentTechnique = effect.Techniques["PointSprites"]; effect.Begin(); foreach (EffectPass CurrentPass in effect.CurrentTechnique.Passes) { CurrentPass.Begin(); device.DrawUserPrimitives(PrimitiveType.PointList, spriteArray, 0, spriteArray_Count); CurrentPass.End(); } effect.End(); device.RenderState.DepthBufferEnable = true; device.RenderState.AlphaBlendEnable = false; device.RenderState.AlphaTestEnable = false; device.RenderState.PointSpriteEnable = false; device.RenderState.DepthBufferWriteEnable = true; }