aboutsummaryrefslogtreecommitdiff
path: root/src/sfml/graphics/VertexArray.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/sfml/graphics/VertexArray.zig')
-rw-r--r--src/sfml/graphics/VertexArray.zig32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/sfml/graphics/VertexArray.zig b/src/sfml/graphics/VertexArray.zig
new file mode 100644
index 0000000..ea4ccb2
--- /dev/null
+++ b/src/sfml/graphics/VertexArray.zig
@@ -0,0 +1,32 @@
+//! Define a set of one or more 2D primitives.
+
+const sf = @import("../sfml.zig");
+
+// CONSTRUCTION ZONE
+
+const VertexArray = @This();
+
+/// Creates a vertex array from a slice of vertices
+pub fn createFromSlice(vertex: []const sf.graphics.Vertex, primitive: sf.graphics.PrimitiveType) !VertexArray {
+ var va = sf.c.sfVertexArray_create();
+ if (va) |vert| {
+ sf.c.sfVertexArray_setPrimitiveType(vert, @enumToInt(primitive));
+ sf.c.sfVertexArray_resize(vert, vertex.len);
+ for (vertex) |v, i|
+ sf.c.sfVertexArray_getVertex(vert, i).* = @bitCast(sf.c.sfVertex, v);
+ return VertexArray{ .ptr = vert };
+ } else return sf.Error.nullptrUnknownReason;
+}
+
+/// Destroys a vertex array
+pub fn destroy(self: VertexArray) void {
+ sf.c.sfVertexArray_destroy(self.ptr);
+}
+
+// Draw function
+pub fn sfDraw(self: VertexArray, window: sf.graphics.RenderWindow, states: ?*sf.c.sfRenderStates) void {
+ sf.c.sfRenderWindow_drawVertexArray(window.ptr, self.ptr, states);
+}
+
+/// Pointer to the csfml structure
+ptr: *sf.c.sfVertexArray,