Exemplo n.º 1
0
        /// <summary>
        ///     Adds a texture to the vertext buffer
        /// </summary>
        /// <param name="texture">Texture to draw</param>
        /// <param name="dc">Coordinates to draw on</param>
        /// <param name="color">Color to use</param>
        /// <param name="isReflection">If true, then color is faded out in y direction</param>
        protected override void _DrawTexture(CD3DTexture texture, SDrawCoords dc, SColorF color, bool isReflection = false)
        {
            //Align the pixels because Direct3D expects the pixels to be the left top corner
            dc.Wx1 -= 0.5f;
            dc.Wy1 -= 0.5f;
            dc.Wx2 -= 0.5f;
            dc.Wy2 -= 0.5f;

            color.A *= CGraphics.GlobalAlpha;
            int c = color.AsColor().ToArgb();
            int c2;

            if (isReflection)
            {
                color.A = 0;
                c2      = color.AsColor().ToArgb();
            }
            else
            {
                c2 = c;
            }

            var vert = new STexturedColoredVertex[4];

            vert[0] = new STexturedColoredVertex(new Vector3(dc.Wx1, -dc.Wy1, dc.Wz), new Vector2(dc.Tx1, dc.Ty1), c);
            vert[1] = new STexturedColoredVertex(new Vector3(dc.Wx1, -dc.Wy2, dc.Wz), new Vector2(dc.Tx1, dc.Ty2), c2);
            vert[2] = new STexturedColoredVertex(new Vector3(dc.Wx2, -dc.Wy2, dc.Wz), new Vector2(dc.Tx2, dc.Ty2), c2);
            vert[3] = new STexturedColoredVertex(new Vector3(dc.Wx2, -dc.Wy1, dc.Wz), new Vector2(dc.Tx2, dc.Ty1), c);
            _AddToVertexBuffer(vert, texture.D3DTexture, _CalculateRotationMatrix(dc.Rotation, dc.Wx1, dc.Wx2, dc.Wy1, dc.Wy2));
        }
Exemplo n.º 2
0
 /// <summary>
 ///     Unloads all Textures and other objects used by Direct3D for rendering
 /// </summary>
 /// <returns></returns>
 public override void Close()
 {
     base.Close();
     STexturedColoredVertex.DisposeDeclaration();
     _VertexBuffer.Dispose();
     _IndexBuffer.Dispose();
     _Device.Dispose();
     _D3D.Dispose();
 }
Exemplo n.º 3
0
 /// <summary>
 ///     Resets the device, all objects in the Direct3D default pool get flushed and need to be recreated
 /// </summary>
 private void _Reset()
 {
     //Dispose all objects in the default pool, those need to be recreated
     STexturedColoredVertex.GetDeclaration(_Device).Dispose();
     _VertexBuffer.Dispose();
     _IndexBuffer.Dispose();
     if (_Device.Reset(_PresentParameters).IsFailure)
     {
         CLog.LogError("Failed to reset the device");
     }
 }
Exemplo n.º 4
0
        private void _InitDevice()
        {
            _AdjustNewBorders();

            _VertexBuffer = new VertexBuffer(_Device, CSettings.VertexBufferElements * (4 * Marshal.SizeOf(typeof(STexturedColoredVertex))), Usage.WriteOnly | Usage.Dynamic,
                                             VertexFormat.Position | VertexFormat.Texture1 | VertexFormat.Diffuse, Pool.Default);

            if (_Device.SetStreamSource(0, _VertexBuffer, 0, Marshal.SizeOf(typeof(STexturedColoredVertex))).IsFailure)
            {
                CLog.LogError("Failed to set stream source");
            }
            _Device.VertexDeclaration = STexturedColoredVertex.GetDeclaration(_Device);

            if (_Device.SetRenderState(RenderState.CullMode, Cull.None).IsFailure)
            {
                CLog.LogError("Failed to set cull mode");
            }
            if (_Device.SetRenderState(RenderState.AlphaBlendEnable, true).IsFailure)
            {
                CLog.LogError("Failed to enable alpha blending");
            }
            if (_Device.SetRenderState(RenderState.Lighting, false).IsFailure)
            {
                CLog.LogError("Failed to disable lighting");
            }
            if (_Device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha).IsFailure)
            {
                CLog.LogError("Failed to set destination blend");
            }
            if (_Device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha).IsFailure)
            {
                CLog.LogError("Failed to set source blend");
            }
            if (_PresentParameters.Multisample != MultisampleType.None)
            {
                if (_Device.SetRenderState(RenderState.MultisampleAntialias, true).IsFailure)
                {
                    CLog.LogError("Failed to set antialiasing");
                }
            }
            if (_Device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear).IsFailure)
            {
                CLog.LogError("Failed to set min filter");
            }
            if (_Device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear).IsFailure)
            {
                CLog.LogError("Failed to set mag filter");
            }
            if (_Device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Linear).IsFailure)
            {
                CLog.LogError("Failed to set mip filter");
            }
            if (_Device.SetSamplerState(0, SamplerState.AddressU, TextureAddress.Clamp).IsFailure)
            {
                CLog.LogError("Failed to set clamping on u");
            }
            if (_Device.SetSamplerState(0, SamplerState.AddressV, TextureAddress.Clamp).IsFailure)
            {
                CLog.LogError("Failed to set claming on v");
            }
            if (_Device.SetTextureStageState(0, TextureStage.AlphaArg1, TextureArgument.Texture).IsFailure)
            {
                CLog.LogError("Failed to set alpha argument 1");
            }
            if (_Device.SetTextureStageState(0, TextureStage.AlphaArg2, TextureArgument.Diffuse).IsFailure)
            {
                CLog.LogError("Failed to set alpha argument 2");
            }
            if (_Device.SetTextureStageState(0, TextureStage.AlphaOperation, TextureOperation.Modulate).IsFailure)
            {
                CLog.LogError("Failed to set alpha operation");
            }

            var indices = new Int16[6];

            indices[0] = 0;
            indices[1] = 1;
            indices[2] = 2;
            indices[3] = 0;
            indices[4] = 2;
            indices[5] = 3;

            _IndexBuffer = new IndexBuffer(_Device, 6 * sizeof(Int16), Usage.WriteOnly, Pool.Managed, true);

            DataStream stream = _IndexBuffer.Lock(0, 0, LockFlags.Discard);

            stream.WriteRange(indices);
            _IndexBuffer.Unlock();
            _Device.Indices = _IndexBuffer;
        }