예제 #1
0
        public void DrawRectangle(Color color, Vector2 location, Vector2 size)
        {
            var col = (RawColor4)color;

            GeometryBuffer.AppendVertices(
                new Detail.Vertex2D(location.X, location.Y, col),

                new Detail.Vertex2D(location.X + size.X, location.Y, col),
                new Detail.Vertex2D(location.X, location.Y + size.Y, col),

                new Detail.Vertex2D(location.X + size.X, location.Y + size.Y, col)
                );

            GeometryBuffer.AppendIndices(
                // top left -> top right
                0,
                1,

                // top right -> bottom right
                1,
                3,

                // bottom right -> bottom left
                3,
                2,

                // bottom left -> top left
                2,
                0
                );

            GeometryBuffer.SetupTexture(Renderer.WhiteView);
            GeometryBuffer.SetPrimitiveType(PrimitiveTopology.LineList);
            GeometryBuffer.Trim();
        }
예제 #2
0
        public GeometryBuffer MakeGeometryBuffer(int size = 1024 * 1024 * 2 /*2mb*/)
        {
            var gbuf = new GeometryBuffer(this, size);

            gbufs.Add(gbuf);
            return(gbuf);
        }
예제 #3
0
        public void FillRectangle(Color color, Vector2 location, Vector2 size)
        {
            var col = (RawColor4)color;

            GeometryBuffer.AppendVertices(
                new Detail.Vertex2D(location.X, location.Y, col),
                new Detail.Vertex2D(location.X + size.X, location.Y, col),
                new Detail.Vertex2D(location.X, location.Y + size.Y, col),
                new Detail.Vertex2D(location.X + size.X, location.Y + size.Y, col)
                );

            GeometryBuffer.AppendIndices(

                1,
                2,
                3,

                0,
                1,
                2

                );

            GeometryBuffer.SetupTexture(Renderer.WhiteView);
            GeometryBuffer.SetPrimitiveType(PrimitiveTopology.TriangleStrip);
            GeometryBuffer.Trim();
        }
예제 #4
0
        public void DrawLines(Color color, Vector2[] points)
        {
            var col = (RawColor4)color;

            points.ToList().ForEach(el => { GeometryBuffer.AppendVertex(new Detail.Vertex2D {
                    Origin = el, Color = col
                }); });

            GeometryBuffer.SetupTexture(Renderer.WhiteView);
            GeometryBuffer.SetPrimitiveType(PrimitiveTopology.LineList);
            GeometryBuffer.Trim();
        }
예제 #5
0
        public void Debug(GeometryBuffer buf)
        {
            var color = new RawColor4(1f, 1f, 1f, 1f);

            buf.AppendVertices(
                new Detail.Vertex2D(0f, 0f, color, 0f, 0f),
                new Detail.Vertex2D(1024, 0f, color, 1f, 0f),
                new Detail.Vertex2D(0f, 512, color, 0f, 1f),
                new Detail.Vertex2D(1024, 512, color, 1f, 1f));
            buf.AppendIndices(0, 1, 2, 1, 2, 3);
            buf.SetupTexture(atlas.Resource);
            buf.Trim();
        }
예제 #6
0
        public void DrawLine(Color color, Vector2 from, Vector2 to)
        {
            var col = (RawColor4)color;

            GeometryBuffer.AppendVertices(
                new Detail.Vertex2D(from.X, from.Y, col),
                new Detail.Vertex2D(to.X, to.Y, col)
                );

            //GeometryBuffer.AppendIndices(new short[]
            //{
            //    0,
            //    1
            //});
            GeometryBuffer.SetPrimitiveType(PrimitiveTopology.LineList);

            GeometryBuffer.Trim();
        }
예제 #7
0
        public void DrawString(GeometryBuffer geometry_buffer, Vector2 location, RawColor4 color, string text,
                               TextAlignment halign = TextAlignment.Near, TextAlignment valign = TextAlignment.Near)
        {
            if (IsDisposed)
            {
                return;
            }

            List <float> line_widths;
            float        height;

            MeasureString(text, out line_widths, out height);

            if (line_widths.Count == 0 && text.Length == 0)
            {
                return;
            }

            float wide         = 0f;
            float space        = Height * 0.35f;
            float highest_char = 0f;

            short vertex_offset = 0;

            switch (halign)
            {
            case TextAlignment.Center:
                wide = location.X - line_widths[0] / 2;
                break;

            case TextAlignment.Far:
                wide = location.X - line_widths[0];
                break;

            default:
                wide = location.X;
                break;
            }

            switch (valign)
            {
            case TextAlignment.Center:
                break;
                location.Y -= height / 2;

            case TextAlignment.Far:
                location.Y -= height;
                break;
            }

            foreach (var c in text)
            {
                if (c == ' ')
                {
                    wide += space;
                    continue;
                }

                if (c == '\n')
                {
                    height += highest_char == 0f ? Height : highest_char;

                    switch (halign)
                    {
                    case TextAlignment.Center:
                        wide = location.X - line_widths[0] / 2;
                        break;

                    case TextAlignment.Far:
                        wide = location.X - line_widths[0];
                        break;

                    default:
                        wide = location.X;
                        break;
                    }
                }

                Detail.Glyph glyph;
                if (atlas.Glyphs.ContainsKey(c))
                {
                    glyph = atlas.Glyphs[c];
                }
                else
                {
                    glyph = atlas.Glyphs['?'];
                }

                geometry_buffer.AppendVertices(
                    new Detail.Vertex2D(wide, location.Y, color, glyph.UV[0].X, glyph.UV[0].Y),

                    new Detail.Vertex2D(wide + glyph.Size.Width, location.Y, color, glyph.UV[1].X, glyph.UV[0].Y),

                    new Detail.Vertex2D(wide, location.Y + glyph.Size.Height, color, glyph.UV[0].X, glyph.UV[1].Y),

                    new Detail.Vertex2D(wide + glyph.Size.Width, location.Y + glyph.Size.Height, color, glyph.UV[1].X,
                                        glyph.UV[1].Y)
                    );

                geometry_buffer.AppendIndices(
                    vertex_offset, (short)(vertex_offset + 1), (short)(vertex_offset + 2),
                    (short)(vertex_offset + 1), (short)(vertex_offset + 2), (short)(vertex_offset + 3)
                    );

                vertex_offset += 4;

                wide += glyph.Size.Width;

                if (glyph.Size.Height > highest_char)
                {
                    highest_char = glyph.Size.Height;
                }
            }

            geometry_buffer.SetPrimitiveType(PrimitiveTopology.TriangleStrip);
            geometry_buffer.SetupTexture(atlas.Resource);
            geometry_buffer.Trim();
        }
예제 #8
0
        public void DrawString(GeometryBuffer geometry_buffer, Vector2 location, RawColor4 color, string text)
        {
            if (IsDisposed)
            {
                return;
            }

            float wide_pos     = location.X;
            float high_pos     = location.Y;
            float highest_char = 0f;

            short vertex_offset = 0;

            var space = Height * 0.35f;

            foreach (var c in text)
            {
                if (c == ' ')
                {
                    wide_pos += space;
                    continue;
                }

                if (c == '\n')
                {
                    wide_pos     = location.X;
                    high_pos    += highest_char == 0f ? Height : highest_char;
                    highest_char = 0f;
                    continue;
                }

                Detail.Glyph glyph;
                if (!atlas.Glyphs.ContainsKey(c))
                {
                    glyph = atlas.Glyphs['?'];
                }
                else
                {
                    glyph = atlas.Glyphs[c];
                }

                if (glyph.Size.Height > highest_char)
                {
                    highest_char = glyph.Size.Height;
                }

                geometry_buffer.AppendVertices(
                    new Detail.Vertex2D(wide_pos, high_pos, color, glyph.UV[0].X, glyph.UV[0].Y),

                    new Detail.Vertex2D(wide_pos + glyph.Size.Width, high_pos, color, glyph.UV[1].X, glyph.UV[0].Y),

                    new Detail.Vertex2D(wide_pos, high_pos + glyph.Size.Height, color, glyph.UV[0].X, glyph.UV[1].Y),

                    new Detail.Vertex2D(wide_pos + glyph.Size.Width, high_pos + glyph.Size.Height, color, glyph.UV[1].X,
                                        glyph.UV[1].Y)
                    );

                geometry_buffer.AppendIndices(
                    vertex_offset, (short)(vertex_offset + 1), (short)(vertex_offset + 2),
                    (short)(vertex_offset + 1), (short)(vertex_offset + 2), (short)(vertex_offset + 3)
                    );

                vertex_offset += 4;

                wide_pos += glyph.Size.Width;
            }

            geometry_buffer.SetPrimitiveType(PrimitiveTopology.TriangleStrip);
            geometry_buffer.SetupTexture(atlas.Resource);
            geometry_buffer.Trim();
        }
예제 #9
0
 public Graphics(GeometryBuffer geobuf)
 {
     GeometryBuffer = geobuf;
 }