Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="anchor"></param>
        /// <param name="margin"></param>
        /// <param name="size"></param>
        /// <param name="zNear"></param>
        /// <param name="zFar"></param>
        /// <param name="fontTexture"></param>
        /// <param name="maxCharCount"></param>
        public UIText(
            System.Windows.Forms.AnchorStyles anchor, System.Windows.Forms.Padding margin,
            System.Drawing.Size size, int zNear, int zFar, IFontTexture fontTexture = null, int maxCharCount = 100)
            : base(anchor, margin, size, zNear, zFar)
        {
            if (fontTexture == null)
            {
                this.fontTexture = FontTexture.Default;
            }                                          // FontResource.Default; }
            else
            {
                this.fontTexture = fontTexture;
            }

            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                                                @"Resources.TextModel.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                                                @"Resources.TextModel.frag"), ShaderType.FragmentShader);
            var map = new AttributeMap();

            map.Add("position", TextModel.strPosition);
            map.Add("uv", TextModel.strUV);
            var model    = new TextModel(maxCharCount);
            var renderer = new Renderer(model, shaderCodes, map);

            this.textModel = model;
            this.Renderer  = renderer;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="content"></param>
        /// <param name="fontTextureService"></param>
        public unsafe void SetText(string content, IFontTexture fontTextureService)
        {
            if (string.IsNullOrEmpty(content))
            {
                if (this.indexBuffer != null)
                {
                    this.indexBuffer.RenderingVertexCount = 0;
                }
                this.content = string.Empty;
                return;
            }

            this.content = content;

            int count = content.Length;

            if (count > this.maxCharCount)
            {
                throw new ArgumentException();
            }
            //{ count = this.maxCharCount; }

            SetupGlyphPositions(content, fontTextureService);
            SetupGlyphTexCoord(content, fontTextureService);
            this.indexBuffer.RenderingVertexCount = count * 4;
        }
Beispiel #3
0
        /// <summary>
        /// Create a label renderer.
        /// </summary>
        /// <param name="maxCharCount">Max char count to display for this label. Careful to set this value because greater <paramref name="maxCharCount"/> means more space ocupied in GPU nemory.</param>
        /// <param name="labelHeight">Label height(in pixels)</param>
        /// <param name="fontTexture">Use which font to render text?</param>
        /// <returns></returns>
        public static LabelRenderer Create(int maxCharCount = 64, int labelHeight = 32, IFontTexture fontTexture = null)
        {
            if (fontTexture == null) { fontTexture = FontTexture.Default; }

            var model = new TextModel(maxCharCount);

            var shaderCodes = new ShaderCode[2];
            shaderCodes[0] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                @"Resources\Label.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                @"Resources\Label.frag"), ShaderType.FragmentShader);

            var map = new AttributeMap();
            map.Add("in_Position", TextModel.strPosition);
            map.Add("in_UV", TextModel.strUV);

            var blendState = new BlendState(BlendingSourceFactor.SourceAlpha, BlendingDestinationFactor.One);

            var renderer = new LabelRenderer(model, shaderCodes, map, blendState);
            renderer.blendState = blendState;
            renderer.fontTexture = fontTexture;
            renderer.LabelHeight = labelHeight;

            return renderer;
        }
        unsafe private void SetupGlyphTexCoord(string content, IFontTexture fontTexture)
        {
            FullDictionary <char, GlyphInfo> charInfoDict = fontTexture.GlyphInfoDictionary;
            IntPtr pointer = this.uvBuffer.MapBuffer(MapBufferAccess.WriteOnly);
            var    array   = (TextModel.GlyphTexCoord *)pointer.ToPointer();
            int    width   = fontTexture.TextureSize.Width;
            int    height  = fontTexture.TextureSize.Height;

            /*
             * 0     3  4     6 8     11 12   15
             * -------  ------- -------  -------
             * |     |  |     | |     |  |     |
             * |     |  |     | |     |  |     |
             * |     |  |     | |     |  |     |
             * -------  ------- -------  -------
             * 1     2  5     6 9     10 13   14
             */
            for (int i = 0; i < content.Length; i++)
            {
                char      ch     = content[i];
                GlyphInfo info   = fontTexture.GlyphInfoDictionary[ch];
                const int shrimp = 0;
                array[i] = new TextModel.GlyphTexCoord(
                    //new vec2(0, 0),
                    //new vec2(0, 1),
                    //new vec2(1, 1),
                    //new vec2(1, 0)
                    new vec2((float)(info.xoffset + shrimp) / (float)width, (float)(info.yoffset) / (float)height),
                    new vec2((float)(info.xoffset + shrimp) / (float)width, (float)(info.yoffset + info.height) / (float)height),
                    new vec2((float)(info.xoffset - shrimp + info.width) / (float)width, (float)(info.yoffset + info.height) / (float)height),
                    new vec2((float)(info.xoffset - shrimp + info.width) / (float)width, (float)(info.yoffset) / (float)height)
                    );
            }
            this.uvBuffer.UnmapBuffer();
        }
Beispiel #5
0
        unsafe private void SetupGlyphPositions(string content, IFontTexture fontTexture)
        {
            FullDictionary <char, GlyphInfo> charInfoDict = fontTexture.GlyphInfoDictionary;

            OpenGL.BindBuffer(BufferTarget.ArrayBuffer, this.positionBufferPtr.BufferId);
            IntPtr pointer = OpenGL.MapBuffer(BufferTarget.ArrayBuffer, MapBufferAccess.ReadWrite);
            var    array = (TextModel.GlyphPosition *)pointer.ToPointer();
            float  currentWidth = 0; int currentHeight = 0;

            /*
             * 0     3  4     7 8     11 12   15
             * -------  ------- -------  -------
             * |     |  |     | |     |  |     |
             * |     |  |     | |     |  |     |
             * |     |  |     | |     |  |     |
             * -------  ------- -------  -------
             * 1     2  5     6 9     10 13   14
             */
            for (int i = 0; i < content.Length; i++)
            {
                char      ch   = content[i];
                GlyphInfo info = charInfoDict[ch];
                array[i] = new TextModel.GlyphPosition(
                    new vec2(currentWidth, currentHeight + fontTexture.GlyphHeight),
                    new vec2(currentWidth, currentHeight),
                    new vec2(currentWidth + info.width, currentHeight),
                    new vec2(currentWidth + info.width, currentHeight + fontTexture.GlyphHeight));
                currentWidth += info.width + fontTexture.GlyphHeight / 10;
            }
            // move to center
            for (int i = 0; i < content.Length; i++)
            {
                TextModel.GlyphPosition position = array[i];

                position.leftUp.x -= currentWidth / 2.0f;
                //position.leftUp.x /= currentWidth / factor;
                position.leftDown.x -= currentWidth / 2.0f;
                //position.leftDown.x /= currentWidth / factor;
                position.rightUp.x -= currentWidth / 2.0f;
                //position.rightUp.x /= currentWidth / factor;
                position.rightDown.x -= currentWidth / 2.0f;
                //position.rightDown.x /= currentWidth / factor;
                position.leftUp.y    -= (currentHeight + fontTexture.GlyphHeight) / 2.0f;
                position.leftDown.y  -= (currentHeight + fontTexture.GlyphHeight) / 2.0f;
                position.rightUp.y   -= (currentHeight + fontTexture.GlyphHeight) / 2.0f;
                position.rightDown.y -= (currentHeight + fontTexture.GlyphHeight) / 2.0f;

                position.leftUp.x    /= (currentHeight + fontTexture.GlyphHeight);
                position.leftDown.x  /= (currentHeight + fontTexture.GlyphHeight);
                position.rightUp.x   /= (currentHeight + fontTexture.GlyphHeight);
                position.rightDown.x /= (currentHeight + fontTexture.GlyphHeight);
                position.leftUp.y    /= (currentHeight + fontTexture.GlyphHeight);
                position.leftDown.y  /= (currentHeight + fontTexture.GlyphHeight);
                position.rightUp.y   /= (currentHeight + fontTexture.GlyphHeight);
                position.rightDown.y /= (currentHeight + fontTexture.GlyphHeight);
                array[i]              = position;
            }
            OpenGL.UnmapBuffer(BufferTarget.ArrayBuffer);
            OpenGL.BindBuffer(BufferTarget.ArrayBuffer, 0);
        }
Beispiel #6
0
        /// <summary>
        /// Adds a font surface to the font.
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="fontTexture"></param>
        /// <returns></returns>
        public FontBuilder AddFontTexture(FontSettings settings, IFontTexture fontTexture)
        {
            Require.That <InvalidOperationException>(font != null,
                                                     "FontBuilder objects cannot be reused.");

            font.AddFontTexture(settings, fontTexture);

            return(this);
        }
        private unsafe void SetupGlyphPositions(string content, IFontTexture fontTexture)
        {
            FullDictionary<char, GlyphInfo> charInfoDict = fontTexture.GlyphInfoDictionary;
            IntPtr pointer = this.positionBuffer.MapBuffer(MapBufferAccess.ReadWrite);
            var array = (TextModel.GlyphPosition*)pointer.ToPointer();
            float currentWidth = 0; int currentHeight = 0;
            /*
             * 0     3  4     7 8     11 12   15
             * -------  ------- -------  -------
             * |     |  |     | |     |  |     |
             * |     |  |     | |     |  |     |
             * |     |  |     | |     |  |     |
             * -------  ------- -------  -------
             * 1     2  5     6 9     10 13   14
             */
            for (int i = 0; i < content.Length; i++)
            {
                char ch = content[i];
                GlyphInfo info = charInfoDict[ch];
                array[i] = new TextModel.GlyphPosition(
                    new vec2(currentWidth, currentHeight + fontTexture.GlyphHeight),
                    new vec2(currentWidth, currentHeight),
                    new vec2(currentWidth + info.width, currentHeight),
                    new vec2(currentWidth + info.width, currentHeight + fontTexture.GlyphHeight));
                currentWidth += info.width + fontTexture.GlyphHeight / 10;
            }
            // move to center
            for (int i = 0; i < content.Length; i++)
            {
                TextModel.GlyphPosition position = array[i];

                position.leftUp.x -= currentWidth / 2.0f;
                //position.leftUp.x /= currentWidth / factor;
                position.leftDown.x -= currentWidth / 2.0f;
                //position.leftDown.x /= currentWidth / factor;
                position.rightUp.x -= currentWidth / 2.0f;
                //position.rightUp.x /= currentWidth / factor;
                position.rightDown.x -= currentWidth / 2.0f;
                //position.rightDown.x /= currentWidth / factor;
                position.leftUp.y -= (currentHeight + fontTexture.GlyphHeight) / 2.0f;
                position.leftDown.y -= (currentHeight + fontTexture.GlyphHeight) / 2.0f;
                position.rightUp.y -= (currentHeight + fontTexture.GlyphHeight) / 2.0f;
                position.rightDown.y -= (currentHeight + fontTexture.GlyphHeight) / 2.0f;

                position.leftUp.x /= (currentHeight + fontTexture.GlyphHeight);
                position.leftDown.x /= (currentHeight + fontTexture.GlyphHeight);
                position.rightUp.x /= (currentHeight + fontTexture.GlyphHeight);
                position.rightDown.x /= (currentHeight + fontTexture.GlyphHeight);
                position.leftUp.y /= (currentHeight + fontTexture.GlyphHeight);
                position.leftDown.y /= (currentHeight + fontTexture.GlyphHeight);
                position.rightUp.y /= (currentHeight + fontTexture.GlyphHeight);
                position.rightDown.y /= (currentHeight + fontTexture.GlyphHeight);
                array[i] = position;
            }
            this.positionBuffer.UnmapBuffer();
        }
        unsafe private void SetupGlyphPositions(string content, IFontTexture fontTexture)
        {
            FullDictionary <char, GlyphInfo> charInfoDict = fontTexture.GlyphInfoDictionary;
            IntPtr pointer = this.positionBuffer.MapBuffer(MapBufferAccess.ReadWrite);
            var    array = (TextModel.GlyphPosition *)pointer.ToPointer();
            float  currentWidth = 0; int currentHeight = 0;

            /*
             * 0     3  4     7 8     11 12   15
             * -------  ------- -------  -------
             * |     |  |     | |     |  |     |
             * |     |  |     | |     |  |     |
             * |     |  |     | |     |  |     |
             * -------  ------- -------  -------
             * 1     2  5     6 9     10 13   14
             */
            for (int i = 0; i < content.Length; i++)
            {
                char      ch   = content[i];
                GlyphInfo info = charInfoDict[ch];
                array[i] = new TextModel.GlyphPosition(
                    new vec2(currentWidth, currentHeight + fontTexture.GlyphHeight),
                    new vec2(currentWidth, currentHeight),
                    new vec2(currentWidth + info.width, currentHeight),
                    new vec2(currentWidth + info.width, currentHeight + fontTexture.GlyphHeight));
                currentWidth += info.width + fontTexture.GlyphHeight / 10;
            }

            switch (this.Alignment)
            {
            case TextAlignment.Center:
                Move2Center(content, array, currentWidth, currentHeight, fontTexture);
                break;

            case TextAlignment.Left:
                Move2Left(content, array, currentWidth, currentHeight, fontTexture);
                break;

            case TextAlignment.Right:
                Move2Right(content, array, currentWidth, currentHeight, fontTexture);
                break;

            default:
                break;
            }

            this.positionBuffer.UnmapBuffer();
        }
Beispiel #9
0
        /// <summary>
        /// Create a text renderer.
        /// </summary>
        /// <param name="maxCharCount">Max char count to display for this label. Careful to set this value because greater <paramref name="maxCharCount"/> means more space ocupied in GPU nemory.</param>
        /// <param name="labelHeight">Label height(in pixels)</param>
        /// <param name="fontTexture">Use which font to render text?</param>
        /// <returns></returns>
        public static TextRenderer Create(int maxCharCount = 64, int labelHeight = 32, IFontTexture fontTexture = null)
        {
            if (fontTexture == null) { fontTexture = FontTexture.Default; }// FontResource.Default; }

            var shaderCodes = new ShaderCode[2];
            shaderCodes[0] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
            @"Resources.TextModel.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
            @"Resources.TextModel.frag"), ShaderType.FragmentShader);
            var map = new AttributeMap();
            map.Add("position", TextModel.strPosition);
            map.Add("uv", TextModel.strUV);
            var model = new TextModel(maxCharCount);
            var renderer = new TextRenderer(model, shaderCodes, map);
            renderer.fontTexture = fontTexture;

            return renderer;
        }
Beispiel #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="maxCharCount">Max char count to display for this label.
        /// Careful to set this value because greater <paramref name="maxCharCount"/> means more space ocupied in GPU nemory.</param>
        /// <param name="labelHeight">Label height(in pixels)</param>
        /// <param name="fontTexture">Use which font to render text?</param>
        public LabelRenderer(int maxCharCount = 64, int labelHeight = 32, IFontTexture fontTexture = null)
            : base(null, null, null, new BlendSwitch(BlendingSourceFactor.SourceAlpha, BlendingDestinationFactor.One))
        {
            GLSwitch blendSwitch = this.SwitchList.Find(x => x is BlendSwitch);

            if (blendSwitch == null)
            {
                throw new Exception();
            }
            this.blendSwitch = blendSwitch;

            if (fontTexture == null)
            {
                this.fontTexture = FontTexture.Default;
            }                                          // FontResource.Default; }
            else
            {
                this.fontTexture = fontTexture;
            }

            this.LabelHeight = labelHeight;

            var model = new TextModel(maxCharCount);

            this.bufferable = model;
            this.model      = model;

            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                                                @"Resources\Label.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                                                @"Resources\Label.frag"), ShaderType.FragmentShader);
            this.shaderCodes = shaderCodes;

            var map = new PropertyNameMap();

            map.Add("in_Position", TextModel.strPosition);
            map.Add("in_UV", TextModel.strUV);
            this.propertyNameMap = map;
        }
Beispiel #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="content"></param>
        /// <param name="fontTextureService"></param>
        public unsafe void SetText(string content, IFontTexture fontTextureService)
        {
            if (string.IsNullOrEmpty(content))
            {
                if (this.indexBuffer != null)
                { this.indexBuffer.RenderingVertexCount = 0; }
                this.content = string.Empty;
                return;
            }

            this.content = content;

            int count = content.Length;
            if (count > this.maxCharCount)
            { throw new ArgumentException(); }
            //{ count = this.maxCharCount; }

            SetupGlyphPositions(content, fontTextureService);
            SetupGlyphTexCoord(content, fontTextureService);
            this.indexBuffer.RenderingVertexCount = count * 4;
        }
Beispiel #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="anchor"></param>
        /// <param name="margin"></param>
        /// <param name="size"></param>
        /// <param name="zNear"></param>
        /// <param name="zFar"></param>
        /// <param name="fontTexture"></param>
        /// <param name="maxCharCount"></param>
        public UIText(
            System.Windows.Forms.AnchorStyles anchor, System.Windows.Forms.Padding margin,
            System.Drawing.Size size, int zNear, int zFar, IFontTexture fontTexture = null, int maxCharCount = 100)
            : base(anchor, margin, size, zNear, zFar)
        {
            if (fontTexture == null)
            { this.fontTexture = FontTexture.Default; }// FontResource.Default; }
            else
            { this.fontTexture = fontTexture; }

            var shaderCodes = new ShaderCode[2];
            shaderCodes[0] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
            @"Resources.TextModel.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
            @"Resources.TextModel.frag"), ShaderType.FragmentShader);
            var map = new AttributeMap();
            map.Add("position", TextModel.strPosition);
            map.Add("uv", TextModel.strUV);
            var model = new TextModel(maxCharCount);
            var renderer = new Renderer(model, shaderCodes, map);

            this.textModel = model;
            this.Renderer = renderer;
        }
Beispiel #13
0
        public static NamedWellRenderer Create(WellModel model, Color wellColor, string name = "", int maxCharCount = 64, int labelHeight = 32, IFontTexture fontTexture = null)
        {
            WellRenderer well = WellRenderer.Create(model);

            well.WellColor = wellColor;
            LabelRenderer label = new LabelRenderer(maxCharCount, labelHeight, fontTexture);

            label.Text = name;
            var renderer = new NamedWellRenderer(well, label);

            return(renderer);
        }
Beispiel #14
0
 private unsafe void SetupGlyphTexCoord(string content, IFontTexture fontTexture)
 {
     FullDictionary<char, GlyphInfo> charInfoDict = fontTexture.GlyphInfoDictionary;
     IntPtr pointer = this.uvBuffer.MapBuffer(MapBufferAccess.WriteOnly);
     var array = (TextModel.GlyphTexCoord*)pointer.ToPointer();
     int width = fontTexture.TextureSize.Width;
     int height = fontTexture.TextureSize.Height;
     /*
      * 0     3  4     6 8     11 12   15
      * -------  ------- -------  -------
      * |     |  |     | |     |  |     |
      * |     |  |     | |     |  |     |
      * |     |  |     | |     |  |     |
      * -------  ------- -------  -------
      * 1     2  5     6 9     10 13   14
      */
     for (int i = 0; i < content.Length; i++)
     {
         char ch = content[i];
         GlyphInfo info = fontTexture.GlyphInfoDictionary[ch];
         const int shrimp = 0;
         array[i] = new TextModel.GlyphTexCoord(
             //new vec2(0, 0),
             //new vec2(0, 1),
             //new vec2(1, 1),
             //new vec2(1, 0)
             new vec2((float)(info.xoffset + shrimp) / (float)width, (float)(info.yoffset) / (float)height),
             new vec2((float)(info.xoffset + shrimp) / (float)width, (float)(info.yoffset + info.height) / (float)height),
             new vec2((float)(info.xoffset - shrimp + info.width) / (float)width, (float)(info.yoffset + info.height) / (float)height),
             new vec2((float)(info.xoffset - shrimp + info.width) / (float)width, (float)(info.yoffset) / (float)height)
             );
     }
     this.uvBuffer.UnmapBuffer();
 }
        private unsafe void Move2Center(string content, GlyphPosition *array, float currentWidth, float currentHeight, IFontTexture fontTexture)
        {
            // move to center
            for (int i = 0; i < content.Length; i++)
            {
                TextModel.GlyphPosition position = array[i];

                position.leftUp.x -= currentWidth / 2.0f;
                //position.leftUp.x /= currentWidth / factor;
                position.leftDown.x -= currentWidth / 2.0f;
                //position.leftDown.x /= currentWidth / factor;
                position.rightUp.x -= currentWidth / 2.0f;
                //position.rightUp.x /= currentWidth / factor;
                position.rightDown.x -= currentWidth / 2.0f;
                //position.rightDown.x /= currentWidth / factor;
                position.leftUp.y    -= (currentHeight + fontTexture.GlyphHeight) / 2.0f;
                position.leftDown.y  -= (currentHeight + fontTexture.GlyphHeight) / 2.0f;
                position.rightUp.y   -= (currentHeight + fontTexture.GlyphHeight) / 2.0f;
                position.rightDown.y -= (currentHeight + fontTexture.GlyphHeight) / 2.0f;

                position.leftUp.x    /= (currentHeight + fontTexture.GlyphHeight);
                position.leftDown.x  /= (currentHeight + fontTexture.GlyphHeight);
                position.rightUp.x   /= (currentHeight + fontTexture.GlyphHeight);
                position.rightDown.x /= (currentHeight + fontTexture.GlyphHeight);
                position.leftUp.y    /= (currentHeight + fontTexture.GlyphHeight);
                position.leftDown.y  /= (currentHeight + fontTexture.GlyphHeight);
                position.rightUp.y   /= (currentHeight + fontTexture.GlyphHeight);
                position.rightDown.y /= (currentHeight + fontTexture.GlyphHeight);
                array[i]              = position;
            }
        }
Beispiel #16
0
 public void AddFontSurface(FontSettings settings, IFontTexture fontSurface)
 {
     throw new NotImplementedException();
 }
Beispiel #17
0
        /// <summary>
        /// Create a text renderer.
        /// </summary>
        /// <param name="maxCharCount">Max char count to display for this label. Careful to set this value because greater <paramref name="maxCharCount"/> means more space ocupied in GPU nemory.</param>
        /// <param name="labelHeight">Label height(in pixels)</param>
        /// <param name="fontTexture">Use which font to render text?</param>
        /// <returns></returns>
        public static TextRenderer Create(int maxCharCount = 64, int labelHeight = 32, IFontTexture fontTexture = null)
        {
            if (fontTexture == null)
            {
                fontTexture = FontTexture.Default;
            }                                                              // FontResource.Default; }

            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                                                @"Resources.TextModel.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                                                @"Resources.TextModel.frag"), ShaderType.FragmentShader);
            var provider = new ShaderCodeArray(shaderCodes);
            var map      = new AttributeMap();

            map.Add("position", TextModel.strPosition);
            map.Add("uv", TextModel.strUV);
            var model    = new TextModel(maxCharCount);
            var renderer = new TextRenderer(model, provider, map);

            renderer.fontTexture = fontTexture;

            return(renderer);
        }
Beispiel #18
0
        public void AddFontSurface(FontSettings settings, IFontTexture fontSurface)
        {
            Require.ArgumentNotNull(fontSurface, nameof(fontSurface));

            fontTextures[settings] = fontSurface;
        }
Beispiel #19
0
        /// <summary>
        /// Create a label renderer.
        /// </summary>
        /// <param name="maxCharCount">Max char count to display for this label. Careful to set this value because greater <paramref name="maxCharCount"/> means more space ocupied in GPU nemory.</param>
        /// <param name="labelHeight">Label height(in pixels)</param>
        /// <param name="fontTexture">Use which font to render text?</param>
        /// <returns></returns>
        public static LabelRenderer Create(int maxCharCount = 64, int labelHeight = 32, IFontTexture fontTexture = null)
        {
            if (fontTexture == null)
            {
                fontTexture = FontTexture.Default;
            }

            var model = new TextModel(maxCharCount);

            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                                                @"Resources\Label.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                                                @"Resources\Label.frag"), ShaderType.FragmentShader);
            var provider = new ShaderCodeArray(shaderCodes);
            var map      = new AttributeMap();

            map.Add("in_Position", TextModel.strPosition);
            map.Add("in_UV", TextModel.strUV);

            var blendState = new BlendState(BlendingSourceFactor.SourceAlpha, BlendingDestinationFactor.One);

            var renderer = new LabelRenderer(model, provider, map, blendState);

            renderer.blendState  = blendState;
            renderer.fontTexture = fontTexture;
            renderer.LabelHeight = labelHeight;

            return(renderer);
        }