public void FillRectangle(Color color, Vector2 location, Vector2 size) { if (!Initialized) { return; } var col = (RawColor4)color; GeometryBuffer.AppendVertices( new Vertex(location.X, location.Y, col), new Vertex(location.X + size.X, location.Y, col), new Vertex(location.X, location.Y + size.Y, col), new Vertex(location.X + size.X, location.Y + size.Y, col) ); GeometryBuffer.AppendIndices( 1, 2, 3, 0, 1, 2 ); GeometryBuffer.SetupTexture(WhiteView); GeometryBuffer.SetPrimitiveType(PrimitiveTopology.TriangleStrip); GeometryBuffer.Trim(); }
public void Debug(GeometryBuffer buf) { var color = new RawColor4(1f, 1f, 1f, 1f); buf.AppendVertices( new Vertex(0f, 0f, color, 0f, 0f), new Vertex(1024, 0f, color, 1f, 0f), new Vertex(0f, 512, color, 0f, 1f), new Vertex(1024, 512, color, 1f, 1f)); buf.AppendIndices(0, 1, 2, 1, 2, 3); buf.SetupTexture(atlas.Resource); buf.Trim(); }
public void DrawRectangle(Color color, Vector2 location, Vector2 size) { if (!Initialized) { return; } var col = (RawColor4)color; GeometryBuffer.AppendVertices( new Vertex(location.X, location.Y, col), new Vertex(location.X + size.X, location.Y, col), new Vertex(location.X, location.Y + size.Y, col), new Vertex(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(WhiteView); GeometryBuffer.SetPrimitiveType(PrimitiveTopology.LineList); GeometryBuffer.Trim(); }
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; } } Glyph glyph; if (atlas.Glyphs.ContainsKey(c)) { glyph = atlas.Glyphs[c]; } else { glyph = atlas.Glyphs['?']; } geometry_buffer.AppendVertices( new Vertex(wide, location.Y, color, glyph.UV[0].X, glyph.UV[0].Y), new Vertex(wide + glyph.Size.Width, location.Y, color, glyph.UV[1].X, glyph.UV[0].Y), new Vertex(wide, location.Y + glyph.Size.Height, color, glyph.UV[0].X, glyph.UV[1].Y), new Vertex(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(); }
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; } 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 Vertex(wide_pos, high_pos, color, glyph.UV[0].X, glyph.UV[0].Y), new Vertex(wide_pos + glyph.Size.Width, high_pos, color, glyph.UV[1].X, glyph.UV[0].Y), new Vertex(wide_pos, high_pos + glyph.Size.Height, color, glyph.UV[0].X, glyph.UV[1].Y), new Vertex(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(); }