Inheritance: ManagedGeometryBuffer
Ejemplo n.º 1
0
 public GwenRenderer()
 {
     zCounter = new ZCounter();
     _guiBuffer = new GUIGeometryBuffer(zCounter);
 }
Ejemplo n.º 2
0
        internal static void DrawText(GUIGeometryBuffer geometryBuffer, Font font, Vector2 position, String text, Color color)
        {
            for(var i = 0; i < text.Length; i++)
            {
                char c = text[i];

                Glyph glyph;
                if (!glyphManager.TryGetGlyphInfo(font, c, out glyph))
                {
                    Log.Warn("Glyph not found for character " + c);
                    continue;
                }

                SubTexture subTexture;
                ResourceHandle<Material> material;

                if (glyphManager.TryGetGlyphImage(font, c, out subTexture, out material))
                {
                    var renderRect = new RectangleF(
                        position.X + glyph.XOffset,
                        position.Y + glyph.BaseLineOffset,
                        glyph.Width,
                        glyph.Height);

                    geometryBuffer.AddRectangle(renderRect,
                        subTexture.LeftTopUV, subTexture.RightTopUV,
                        subTexture.RightBottomUV, subTexture.LeftBottomUV,
                        material, color);
                }

                if (i < text.Length-1){
                    var kern = glyphManager.GetKerning(font, text[i], text[i+1]);
                    position.X += glyph.Advance + kern.X;
                    position.Y += kern.Y;
                }
            }
        }
Ejemplo n.º 3
0
        internal static void DrawText(GUIGeometryBuffer geometryBuffer, Flood.GUI.Font font, Vector2 position, String text, Color color)
        {
            var ttfont = font.EngineFont.Resolve();
            for(var i = 0; i < text.Length; i++)
            {
                char c = text[i];

                Glyph glyph;
                var foundGlyph = ttfont.GetGlyphInfo(c, font.Size, out glyph);
                if (!foundGlyph)
                {
                    Log.Warn("Glyph not found for character " + c);
                    continue;
                }

                bool drawSubtexture = true;
                SubTexture subTexture;
                if(!glyphCache.TryGetGlyph(font, c, out subTexture))
                {
                    var imageHandle = ttfont.CreateGlyphImage(c, font.Size);
                    if (imageHandle.Id == ResourceHandle<Resource>.Invalid)
                    {
                        drawSubtexture = false;
                    }
                    else
                    {
                        var subTextureFound = textureAtlas.GetImageSubTexture(imageHandle, out subTexture);
                        if (!subTextureFound)
                        {
                            textureAtlas.AddImage(imageHandle);
                            subTextureFound = textureAtlas.GetImageSubTexture(imageHandle, out subTexture);
                            if (subTextureFound)
                            {
                                glyphCache.AddGlyph(font, c, subTexture);
                            }
                            else
                            {
                                Log.Warn("subTexture not Found\n");
                                continue;
                            }
                        }
                    }
                }

                if (drawSubtexture)
                {

                    var renderRect = new RectangleF(
                        position.X + glyph.XOffset,
                        position.Y + glyph.BaseLineOffset,
                        glyph.Width,
                        glyph.Height);

                    geometryBuffer.AddRectangle(renderRect,subTexture.LeftTopUV,subTexture.RightTopUV,subTexture.RightBottomUV,subTexture.LeftBottomUV,textMaterial,color);
                }

                if (i < text.Length-1){
                    var kern = ttfont.GetKerning(text[i], text[i+1], font.Size);
                    position.X += glyph.Advance + kern.X;
                    position.Y += kern.Y;
                }
            }
        }