/// <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;
        }
        protected override void Initialize()
        {
            linerenderer = new LineRenderer((SpaceShooterGame)game);
            linerenderer.OnCreateDevice();

            discrenderer = new DiscRenderer((SpaceShooterGame)game);
            discrenderer.OnCreateDevice();

            sphererenderer = new SphereRenderer((SpaceShooterGame)game);
            sphererenderer.OnCreateDevice();

            pointrenderer = new PointRenderer(Game.Content.Load <Effect>("shaders/pointeffect"));
            PointSpriteHelper.Initialize();

            particles.Initialize();
            boltManager.Initialize();


            spriteBatch = new SpriteBatch(GraphicsDevice);

            serif    = Game.Content.Load <SpriteFont>(@"fonts\serif");
            serifbig = Game.Content.Load <SpriteFont>(@"fonts\serifbig");
            gothic   = Game.Content.Load <SpriteFont>(@"fonts\gothic");


            hudsheet   = FrameworkCore.content.Load <Texture2D>(@"textures\hudsheet");
            eventsheet = FrameworkCore.content.Load <Texture2D>(@"textures\eventsheet");



            modelDebris01 = FrameworkCore.Game.Content.Load <Model>(@"meshes\debris01");
            modelDebris02 = FrameworkCore.Game.Content.Load <Model>(@"meshes\debris02");

            modelAsteroid01 = FrameworkCore.Game.Content.Load <Model>(@"meshes\asteroid01");
            modelAsteroid02 = FrameworkCore.Game.Content.Load <Model>(@"meshes\asteroid02");

            modelBeam01 = FrameworkCore.Game.Content.Load <Model>(@"meshes\beam");

            modelPlanet     = FrameworkCore.Game.Content.Load <Model>(@"meshes\planet");
            modelPlanetTiny = FrameworkCore.Game.Content.Load <Model>(@"meshes\planettiny");


            if (modelArray == null)
            {
                int i, j = modelFiles.GetLength(0);
                modelArray = new Model[j];
                for (i = 0; i < j; i++)
                {
                    modelArray[i] = content.Load <Model>(modelFiles[i]);
                }
            }

            //pre load all the textures.
            if (textureArray == null)
            {
                int i, j = modelFiles.GetLength(0);
                textureArray = new Texture2D[j];
                for (i = 0; i < j; i++)
                {
                    textureArray[i] = ((BasicEffect)FrameworkCore.ModelArray[i].Meshes[0].MeshParts[0].Effect).Texture;
                }
            }

            Meshrenderer.Initialize();
            playerMeshRenderer.Initialize();


            meshRenderer.LoadContent();
            playerMeshRenderer.LoadContent();


#if XBOX
            audioEngine = new AudioEngine("XboxContent/xbox/serp6.xgs");
            soundBank   = new SoundBank(audioEngine, "XboxContent/xbox/Sound Bank.xsb");
            waveBank    = new WaveBank(audioEngine, "XboxContent/xbox/Wave Bank.xwb");
#else
            try
            {
                audioEngine = new AudioEngine("WindowsContent\\win\\serp6.xgs");
                soundBank   = new SoundBank(audioEngine, "WindowsContent\\win\\Sound Bank.xsb");
                waveBank    = new WaveBank(audioEngine, "WindowsContent\\win\\Wave Bank.xwb");
            }
            catch
            {
#if SDL2
                if (!YesNoPopup.Show(
                        "Audio Error",
                        "There was a problem initializing the audio engine.\n\nTo resolve this:\n1. Right-click on your volume control.\n2. Select \"Playback devices\"\n3. Right-click on \"Digital Output\"\n4. Select \"Set as Default Device\"\n\nDo you want to continue with sound disabled?"))
#else
                if (MessageBox.Show(
                        "There was a problem initializing the audio engine.\n\nTo resolve this:\n1. Right-click on your volume control.\n2. Select \"Playback devices\"\n3. Right-click on \"Digital Output\"\n4. Select \"Set as Default Device\"\n\nDo you want to continue with sound disabled?",
                        "Audio Error", MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Error) == DialogResult.No)
#endif
                {
                    this.Exit();
                }
            }
#endif

            try
            {
                SoundCategory = audioEngine.GetCategory("Default");
                MusicCategory = audioEngine.GetCategory("Music");
            }
            catch
            {
            }



            SetSoundVolume();
            SetMusicVolume();



            bloomComponent.Initialize();


            base.Initialize();
        }
Esempio n. 3
0
        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
            {
            }
        }
        /// <summary>
        /// Draws the particle system.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            try
            {
                GraphicsDevice device = GraphicsDevice;

                SetCamera(Camera.View, Camera.Projection);

                // Restore the vertex buffer contents if the graphics device was lost.
                if (vertexBuffer.IsContentLost)
                {
                    vertexBuffer.SetData(particles);
                }

                // If there are any particles waiting in the newly added queue,
                // we'd better upload them to the GPU ready for drawing.
                if (firstNewParticle != firstFreeParticle)
                {
                    AddNewParticlesToVertexBuffer();
                }

                // If there are any active particles, draw them now!
                if (firstActiveParticle != firstFreeParticle)
                {
                    SetParticleRenderStates(device);

                    // Set an effect parameter describing the viewport size. This is needed
                    // to convert particle sizes into screen space point sprite sizes.
                    effectViewportHeightParameter.SetValue(device.Viewport.Height);

                    // Set an effect parameter describing the current time. All the vertex
                    // shader particle animation is keyed off this value.
                    effectTimeParameter.SetValue(currentTime);

                    // Set the particle vertex buffer and vertex declaration.
                    device.SetVertexBuffer(vertexBuffer);

                    //foreach (EffectPass pass in particleEffect.CurrentTechnique.Passes)
                    for (int i = 0; i < particleEffect.CurrentTechnique.Passes.Count; ++i)
                    {
                        particleEffect.CurrentTechnique.Passes[i].Apply();

#if SDL2
                        if (firstActiveParticle < firstFreeParticle)
                        {
                            // If the active particles are all in one consecutive range,
                            // we can draw them all in a single call.
                            device.DrawPrimitives(PrimitiveType.PointListEXT,
                                                  firstActiveParticle,
                                                  firstFreeParticle - firstActiveParticle);
                        }
                        else
                        {
                            // If the active particle range wraps past the end of the queue
                            // back to the start, we must split them over two draw calls.
                            device.DrawPrimitives(PrimitiveType.PointListEXT,
                                                  firstActiveParticle,
                                                  particles.Length - firstActiveParticle);

                            if (firstFreeParticle > 0)
                            {
                                device.DrawPrimitives(PrimitiveType.PointListEXT,
                                                      0,
                                                      firstFreeParticle);
                            }
                        }
#endif
                    }

                    // Reset a couple of the more unusual renderstates that we changed,
                    // so as not to mess up any other subsequent drawing.
                    PointSpriteHelper.Disable();
                    if (device.DepthStencilState.DepthBufferEnable)
                    {
                        device.DepthStencilState = DepthStencilState.Default;
                    }
                    else
                    {
                        device.DepthStencilState = Helpers.DepthWrite;
                    }
                }
            }
            catch
            {
            }

            drawCounter++;
        }