Circle! (black and 8 sided)
This commit is contained in:
parent
5ecc42ab89
commit
64c94fd1b8
57
src/main.zig
57
src/main.zig
@ -24,25 +24,60 @@ export fn init() void {
|
|||||||
|
|
||||||
std.log.info("Vertex buffers len: {}", .{state.bind.vertex_buffers.len});
|
std.log.info("Vertex buffers len: {}", .{state.bind.vertex_buffers.len});
|
||||||
|
|
||||||
var triangleVerts = [_]f32{
|
const vertexCount = 8;
|
||||||
// positions colors
|
const radius: f32 = 0.4;
|
||||||
0.0, 0.5, 0.5, 1.0, 0.0, 0.0, 1.0,
|
|
||||||
0.5, -0.5, 0.5, 0.0, 1.0, 0.0, 1.0,
|
const cX: f32 = 0;
|
||||||
-0.5, -0.5, 0.5, 0.0, 0.0, 1.0, 1.0,
|
const cY: f32 = 0;
|
||||||
0.7, 0.5, 0.5, 0.0, 1.0, 0.0, 1.0,
|
|
||||||
};
|
const attributesCount = 7;
|
||||||
|
|
||||||
|
var triangleVerts = std.mem.zeroes([vertexCount * attributesCount]f32);
|
||||||
|
|
||||||
|
const angleDiff: f32 = 1 / @as(f32, @floatFromInt(vertexCount));
|
||||||
|
|
||||||
|
for (0..vertexCount) |i| {
|
||||||
|
const pi: f32 = @floatCast(std.math.pi);
|
||||||
|
const angle: f32 = @as(f32, @floatFromInt(i)) * angleDiff * pi * 2;
|
||||||
|
|
||||||
|
const x = radius * @cos(angle) + cX;
|
||||||
|
const y = radius * @sin(angle) + cY;
|
||||||
|
|
||||||
|
const si = i * attributesCount;
|
||||||
|
triangleVerts[si + 0] = x;
|
||||||
|
triangleVerts[si + 1] = y;
|
||||||
|
triangleVerts[si + 2] = 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// var triangleVerts = [_]f32{
|
||||||
|
// // positions colors
|
||||||
|
// 0.0, 0.5, 0.5, 1.0, 0.0, 0.0, 1.0,
|
||||||
|
// 0.5, -0.5, 0.5, 0.0, 1.0, 0.0, 1.0,
|
||||||
|
// -0.5, -0.5, 0.5, 0.0, 0.0, 1.0, 1.0,
|
||||||
|
// 0.7, 0.5, 0.5, 0.0, 1.0, 0.0, 1.0,
|
||||||
|
// };
|
||||||
|
|
||||||
state.bind.vertex_buffers[0] = sg.makeBuffer(.{
|
state.bind.vertex_buffers[0] = sg.makeBuffer(.{
|
||||||
.data = sg.asRange(&triangleVerts),
|
.data = sg.asRange(&triangleVerts),
|
||||||
});
|
});
|
||||||
|
|
||||||
const indexBuffer = [_]u16{
|
const trisCount = vertexCount - 2;
|
||||||
0, 1, 2,
|
|
||||||
0, 3, 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
var indexBuffer: [trisCount * 3]u16 = undefined;
|
||||||
state.indexCount = indexBuffer.len;
|
state.indexCount = indexBuffer.len;
|
||||||
|
|
||||||
|
// const indexBuffer = [_]u16{
|
||||||
|
// 0, 1, 2,
|
||||||
|
// 0, 2, 3,
|
||||||
|
// };
|
||||||
|
|
||||||
|
for (0..trisCount) |tri| {
|
||||||
|
const triu: u16 = @intCast(tri);
|
||||||
|
indexBuffer[tri * 3 + 0] = 0;
|
||||||
|
indexBuffer[tri * 3 + 1] = triu + 1;
|
||||||
|
indexBuffer[tri * 3 + 2] = triu + 2;
|
||||||
|
}
|
||||||
|
|
||||||
state.bind.index_buffer = sg.makeBuffer(.{
|
state.bind.index_buffer = sg.makeBuffer(.{
|
||||||
.type = .INDEXBUFFER,
|
.type = .INDEXBUFFER,
|
||||||
.data = sg.asRange(&indexBuffer),
|
.data = sg.asRange(&indexBuffer),
|
||||||
|
Loading…
Reference in New Issue
Block a user