Ejemplo n.º 1
0
        private bool UpdateSentence2(ref DSentence sentence, string text, int positionX, int positionY, float red, float green, float blue, DeviceContext deviceContext)
        {
            // Store the color of the sentence.
            sentence.red   = red;
            sentence.green = green;
            sentence.blue  = blue;

            // Get the number of the letter in the sentence.
            var numLetters = sentence.MaxLength;

            // Check for possible buffer overflow.
            if (numLetters > sentence.MaxLength)
            {
                return(false);
            }

            // Calculate the X and Y pixel position on screen to start drawing to.
            var drawX = -(ScreenWidth >> 1) + positionX;
            var drawY = (ScreenHeight >> 1) - positionY;

            // Use the font class to build the vertex array from the sentence text and sentence draw location.
            List <DFont.DVertexType> vertices;

            Font.BuildVertexArray(out vertices, text, drawX, drawY);

            // Empty all remaining vertices
            for (int i = text.Length; i < sentence.MaxLength; i++)
            {
                var emptyVertex = new DFont.DVertexType();
                emptyVertex.position = Vector3.Zero;
                emptyVertex.texture  = Vector2.Zero;
                vertices.Add(emptyVertex);
            }

            DataStream mappedResource;

            #region Vertex Buffer
            // Lock the vertex buffer so it can be written to.
            deviceContext.MapSubresource(sentence.VertexBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);

            // Copy the data into the vertex buffer.
            mappedResource.WriteRange <DFont.DVertexType>(vertices.ToArray());

            // Unlock the vertex buffer.
            deviceContext.UnmapSubresource(sentence.VertexBuffer, 0);
            #endregion

            vertices?.Clear();
            vertices = null;

            return(true);
        }
        public bool UpdateSentence2(DFont font, string text, int positionX, int positionY, float red, float green, float blue, DeviceContext deviceContext)
        {
            // Store the color of the sentence.
            PixelColour = new Vector4(red, green, blue, 1.0f);

            // Get the number of letters in the sentence.
            var numLetters = text.Length;

            // Check for possible buffer overflow.
            if (numLetters > MaxLength)
            {
                return(false);
            }

            // Calculate the X and Y pixel position on screen to start drawing to.
            var drawX = -(ScreenWidth >> 1) + positionX;
            var drawY = (ScreenHeight >> 1) - positionY;

            // Use the font class to build the vertex array from the sentence text and sentence draw location.
            List <DFont.DVertexType> vertices;

            font.BuildVertexArray(out vertices, text, drawX, drawY);

            // Empty all remaining vertices
            for (int i = text.Length; i < MaxLength; i++)
            {
                var emptyVertex = new DFont.DVertexType();
                emptyVertex.position = Vector3.Zero;
                emptyVertex.texture  = Vector2.Zero;
                vertices.Add(emptyVertex);
            }

            DataStream mappedResource;

            #region Vertex Buffer
            // Lock the vertex buffer so it can be written to.
            deviceContext.MapSubresource(VertexBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);

            // Copy the data into the vertex buffer.
            mappedResource.WriteRange <DFont.DVertexType>(vertices.ToArray());

            // Unlock the vertex buffer.
            deviceContext.UnmapSubresource(VertexBuffer, 0);
            #endregion

            // If shadowed then do the same for the second vertex buffer but offset by one pixel.
            if (Shadowed)
            {
                // Perform same mapping and writings code as above except for the shadows offset position for the effect.
            }

            vertices?.Clear();
            vertices = null;

            return(true);
        }