Exemple #1
0
        public void Render(Device Device3D, DeviceInfo deviceInfo)
        {
            Update();
            try
            {
                if (m_ActiveParticles.Count > 0)
                {
                    Device3D.Transform.World = this.World;
                    // il faut désactiver la lumière sinon les couleurs ne sont pas utilisées
                    Device3D.RenderState.Lighting = false;

                    // Set the render states for using point sprites
                    Device3D.RenderState.ZBufferWriteEnable = false;
                    Device3D.RenderState.AlphaBlendEnable   = true;
                    Device3D.RenderState.SourceBlend        = Blend.SourceAlpha;
                    Device3D.RenderState.DestinationBlend   = Blend.One;

                    Device3D.TextureState[0].ColorOperation = TextureOperation.Modulate;
                    Device3D.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
                    Device3D.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;
                    Device3D.TextureState[0].AlphaOperation = TextureOperation.Modulate;
                    Device3D.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
                    Device3D.TextureState[0].AlphaArgument2 = TextureArgument.Diffuse;

                    Device3D.SetTexture(0, m_Texture.GetTexture());
                    Device3D.RenderState.PointSpriteEnable = true;
                    Device3D.RenderState.PointScaleEnable  = true;
                    Device3D.RenderState.PointSize         = m_PointSize;
                    Device3D.RenderState.PointSizeMin      = m_PointSizeMin;
                    Device3D.RenderState.PointScaleA       = m_PointScaleA;
                    Device3D.RenderState.PointScaleB       = m_PointScaleB;
                    Device3D.RenderState.PointScaleC       = m_PointScaleC;

                    Device3D.VertexFormat = CustomVertex.PositionColoredTextured.Format;

                    // Set up the vertex buffer to be rendered
                    Device3D.SetStreamSource(0, m_VB, 0);

                    CustomVertex.PositionColoredTextured[] vertices = null;
                    int numParticlesToRender = 0;

                    // Lock the vertex buffer.  We fill the vertex buffer in small
                    // chunks, using LockFlags.NoOverWrite.  When we are done filling
                    // each chunk, we call DrawPrim, and lock the next chunk.  When
                    // we run out of space in the vertex buffer, we start over at
                    // the beginning, using LockFlags.Discard.

                    m_BaseParticle += m_Flush;

                    if (m_BaseParticle >= m_Discard)
                    {
                        m_BaseParticle = 0;
                    }

                    int count = 0;
                    vertices = (CustomVertex.PositionColoredTextured[])m_VB.Lock(m_BaseParticle * DXHelp.GetTypeSize(typeof(CustomVertex.PositionColoredTextured)), typeof(CustomVertex.PositionColoredTextured), (m_BaseParticle != 0) ? LockFlags.NoOverwrite : LockFlags.Discard, m_Flush);
                    foreach (Particle p in m_ActiveParticles)
                    {
                        vertices[count].X     = p.Position.X;
                        vertices[count].Y     = p.Position.Y;
                        vertices[count].Z     = p.Position.Z;
                        vertices[count].Color = unchecked ((int)p.Color.ToArgb());
                        count++;

                        if (++numParticlesToRender == m_Flush)
                        {
                            // Done filling this chunk of the vertex buffer.  Lets unlock and
                            // draw this portion so we can begin filling the next chunk.

                            m_VB.Unlock();

                            Device3D.DrawPrimitives(PrimitiveType.PointList, m_BaseParticle, numParticlesToRender);

                            // Lock the next chunk of the vertex buffer.  If we are at the
                            // end of the vertex buffer, LockFlags.Discard the vertex buffer and start
                            // at the beginning.  Otherwise, specify LockFlags.NoOverWrite, so we can
                            // continue filling the VB while the previous chunk is drawing.
                            m_BaseParticle += m_Flush;

                            if (m_BaseParticle >= m_Discard)
                            {
                                m_BaseParticle = 0;
                            }

                            vertices = (CustomVertex.PositionColoredTextured[])m_VB.Lock(m_BaseParticle * DXHelp.GetTypeSize(typeof(CustomVertex.PositionColoredTextured)), typeof(CustomVertex.PositionColoredTextured), (m_BaseParticle != 0) ? LockFlags.NoOverwrite : LockFlags.Discard, m_Flush);
                            count    = 0;

                            numParticlesToRender = 0;
                        }
                    }

                    // Unlock the vertex buffer
                    m_VB.Unlock();
                    // Render any remaining particles
                    if (numParticlesToRender > 0)
                    {
                        Device3D.DrawPrimitives(PrimitiveType.PointList, m_BaseParticle, numParticlesToRender);
                    }

                    // Reset render states
                    Device3D.RenderState.PointSpriteEnable = false;
                    Device3D.RenderState.PointScaleEnable  = false;

                    Device3D.RenderState.ZBufferWriteEnable = true;
                    Device3D.RenderState.AlphaBlendEnable   = false;

                    //Console.AddLine(m_ActiveParticles[0].Position.ToString() + "Alpha:" + m_ActiveParticles[0].Color.A);
                }
            }
            catch (DirectXException d3de)
            {
                Console.AddLine("Unable to Render Particles");
                Console.AddLine(d3de.ErrorString);
            }
            catch (Exception e)
            {
                Console.AddLine("Unable to Render Particles");
                Console.AddLine(e.Message);
            }
        }
Exemple #2
0
        /// <summary>
        /// Draw the console if it is visible
        /// </summary>
        public void Render(Device Device3D, DeviceInfo deviceInfo)
        {
            if (m_bVisible)
            {
                Device3D.RenderState.FogEnable = false;

                // determine how much of the console will be visible based on whether it is opening,
                // open, or closing
                if (m_bOpening && m_Percent < m_MaxPercent)
                {
                    m_Percent += 0.05f;
                }
                else if (m_bClosing && m_Percent >= m_ClosingTo)
                {
                    m_Percent -= 0.05f;
                    if (m_Percent <= m_ClosingTo)
                    {
                        m_bClosing = false;
                        m_bVisible = m_ClosingTo > 0.0f;

                        m_bOpening  = m_bVisible;
                        m_ClosingTo = 0.0f;
                    }
                }

                // render the console background
                try
                {
                    int line = (int)((m_Percent * Device3D.Viewport.Height) - 5 - m_pFont.LineHeight);

                    if (line > 5)
                    {
                        // draw the image to the device
                        try
                        {
                            CustomVertex.TransformedTextured[] data = new CustomVertex.TransformedTextured[4];
                            data[0].X  = Device3D.Viewport.Width;
                            data[0].Y  = 0.0f - (1.0f - m_Percent) * Device3D.Viewport.Height;
                            data[0].Z  = 0.0f;
                            data[0].Tu = 1.0f;
                            data[0].Tv = 0.0f;
                            data[1].X  = 0.0f;
                            data[1].Y  = 0.0f - (1.0f - m_Percent) * Device3D.Viewport.Height;
                            data[1].Z  = 0.0f;
                            data[1].Tu = 0.0f;
                            data[1].Tv = 0.0f;
                            data[2].X  = Device3D.Viewport.Width;
                            data[2].Y  = Device3D.Viewport.Height - (1.0f - m_Percent) * Device3D.Viewport.Height;
                            data[2].Z  = 0.0f;
                            data[2].Tu = 1.0f;
                            data[2].Tv = 1.0f;
                            data[3].X  = 0.0f;
                            data[3].Y  = Device3D.Viewport.Height - (1.0f - m_Percent) * Device3D.Viewport.Height;
                            data[3].Z  = 0.0f;
                            data[3].Tu = 0.0f;
                            data[3].Tv = 1.0f;

                            VertexBuffer vb = new VertexBuffer(typeof(CustomVertex.TransformedTextured), 4,
                                                               Device3D, Usage.WriteOnly, CustomVertex.TransformedTextured.Format,
                                                               Pool.Default);

                            vb.SetData(data, 0, 0);

                            Device3D.SetStreamSource(0, vb, 0);
                            Device3D.VertexFormat         = CustomVertex.TransformedTextured.Format;
                            Device3D.RenderState.CullMode = Microsoft.DirectX.Direct3D.Cull.Clockwise;

                            // Set the texture
                            Device3D.SetTexture(0, m_Image.GetTexture());

                            // Render the face
                            Device3D.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
                        }
                        catch (DirectXException d3de)
                        {
                            Console.AddLine("Unable to display console ");
                            Console.AddLine(d3de.ErrorString);
                        }
                        catch (Exception e)
                        {
                            Console.AddLine("Unable to display console ");
                            Console.AddLine(e.Message);
                        }

                        m_pFont.DrawText(2, line, Color.White, m_Entryline.ToString());
                        line -= (int)m_pFont.LineHeight;

                        foreach (String entry in m_Entries)
                        {
                            if (line < 5 || line > 300)
                            {
                                //								Debug.WriteLine("line is " + line);
                            }
                            if (line > 5)
                            {
                                m_pFont.DrawText(2, line, Color.White, entry);
                                line -= (int)m_pFont.LineHeight;
                            }
                        }
                    }
                }
                catch (DirectXException d3de)
                {
                    Debug.WriteLine("unable to render console");
                    Debug.WriteLine(d3de.ErrorString);
                }
                catch (Exception e)
                {
                    Debug.WriteLine("unable to render console");
                    Debug.WriteLine(e.Message);
                }

                Device3D.RenderState.FogEnable = deviceInfo.FogEnabled;
            }
        }
        public void Render(Device Device3D, DeviceInfo deviceInfo)
        {
            try
            {
                Device3D.RenderState.FogEnable = false;

                CustomVertex.TransformedTextured[] data = new CustomVertex.TransformedTextured[4];
                data[0].X  = 0.0f;
                data[0].Y  = 0.0f;
                data[0].Z  = 1.0f;
                data[0].Tu = 0.0f;
                data[0].Tv = 0.0f;
                data[1].X  = Device3D.Viewport.Width;
                data[1].Y  = 0.0f;
                data[1].Z  = 1.0f;
                data[1].Tu = 1.0f;
                data[1].Tv = 0.0f;
                data[2].X  = 0.0f;
                data[2].Y  = Device3D.Viewport.Height;
                data[2].Z  = 1.0f;
                data[2].Tu = 0.0f;
                data[2].Tv = 1.0f;
                data[3].X  = Device3D.Viewport.Width;
                data[3].Y  = Device3D.Viewport.Height;
                data[3].Z  = 1.0f;
                data[3].Tu = 1.0f;
                data[3].Tv = 1.0f;

                m_vb.SetData(data, 0, 0);

                Device3D.SetStreamSource(0, m_vb, 0);
                Device3D.VertexFormat = CustomVertex.TransformedTextured.Format;

                // Set the texture
                Device3D.SetTexture(0, m_Background.GetTexture());

                // Render the screen background
                Device3D.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);

                // Set diffuse blending for alpha set in vertices.
                Device3D.RenderState.AlphaBlendEnable = true;
                Device3D.RenderState.SourceBlend      = Blend.SourceAlpha;
                Device3D.RenderState.DestinationBlend = Blend.InvSourceAlpha;

                // Enable alpha testing (skips pixels with less than a certain alpha.)
                if (Device3D.DeviceCaps.AlphaCompareCaps.SupportsGreaterEqual)
                {
                    Device3D.RenderState.AlphaTestEnable = true;
                    Device3D.RenderState.ReferenceAlpha  = 0x08;
                    Device3D.RenderState.AlphaFunction   = Compare.GreaterEqual;
                }
                // copy on the buttons
                foreach (ImageButton button in m_buttons)
                {
                    button.HoverTest(m_MousePoint);
                    if (m_bMouseIsDown && !m_bMouseWasDown)
                    {
                        button.ClickTest(m_MousePoint);
                    }

                    button.Render(Device3D, deviceInfo);
                }
                m_bMouseWasDown = m_bMouseIsDown;

                // draw cursor
                Rectangle mouserect = new Rectangle(m_MousePoint, m_Cursor.GetSize());
                try
                {
                    data[0].X  = (float)mouserect.X;
                    data[0].Y  = (float)mouserect.Y;
                    data[0].Z  = 0.0f;
                    data[0].Tu = 0.0f;
                    data[0].Tv = 0.0f;
                    data[1].X  = (float)(mouserect.X + mouserect.Width);
                    data[1].Y  = (float)mouserect.Y;
                    data[1].Z  = 0.0f;
                    data[1].Tu = 1.0f;
                    data[1].Tv = 0.0f;
                    data[2].X  = (float)mouserect.X;
                    data[2].Y  = (float)(mouserect.Y + mouserect.Height);
                    data[2].Z  = 0.0f;
                    data[2].Tu = 0.0f;
                    data[2].Tv = 1.0f;
                    data[3].X  = (float)(mouserect.X + mouserect.Width);
                    data[3].Y  = (float)(mouserect.Y + mouserect.Height);
                    data[3].Z  = 0.0f;
                    data[3].Tu = 1.0f;
                    data[3].Tv = 1.0f;

                    m_vb.SetData(data, 0, 0);

                    Device3D.SetStreamSource(0, m_vb, 0);
                    Device3D.VertexFormat = CustomVertex.TransformedTextured.Format;

                    // Set the texture
                    Device3D.SetTexture(0, m_Cursor.GetTexture());

                    // Set diffuse blending for alpha set in vertices.
                    Device3D.RenderState.AlphaBlendEnable = true;
                    Device3D.RenderState.SourceBlend      = Blend.SourceAlpha;
                    Device3D.RenderState.DestinationBlend = Blend.InvSourceAlpha;

                    // Enable alpha testing (skips pixels with less than a certain alpha.)
                    if (Device3D.DeviceCaps.AlphaCompareCaps.SupportsGreaterEqual)
                    {
                        Device3D.RenderState.AlphaTestEnable = true;
                        Device3D.RenderState.ReferenceAlpha  = 0x08;
                        Device3D.RenderState.AlphaFunction   = Compare.GreaterEqual;
                    }
                    // Render the face
                    Device3D.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
                }
                catch (DirectXException d3de)
                {
                    Console.AddLine("Unable to display cursor ");
                    Console.AddLine(d3de.ErrorString);
                }
                catch (Exception e)
                {
                    Console.AddLine("Unable to display cursor ");
                    Console.AddLine(e.Message);
                }

                Device3D.RenderState.FogEnable = deviceInfo.FogEnabled;
            }
            catch (DirectXException d3de)
            {
                Console.AddLine("Error rendering Option Screen ");
                Console.AddLine(d3de.ErrorString);
            }
            catch (Exception e)
            {
                Console.AddLine("Error rendering Option Screen ");
                Console.AddLine(e.Message);
            }
        }