#load "camera"
#load "mesh"
#load "vecmath"
+#load "chunk"
// Onyx library code
#load "stb_truetype"
--- /dev/null
+use package core
+
+Block :: #distinct u32;
+Block_Empty :: cast(Block) 0;
+
+block_make :: (red, green, blue: f32, brightness: f32) -> Block {
+ r := cast(u32) (red * 16.0f);
+ g := cast(u32) (green * 16.0f);
+ b := cast(u32) (blue * 16.0f);
+ i := cast(u32) (brightness * 16.0f);
+
+ return ~~(i << 12 | b << 8 | g << 4 | r);
+}
+
+Chunk_Size :: 16
+
+Chunk :: struct {
+ blocks: [] Block;
+}
+
+chunk_make :: (allocator := context.allocator) -> ^Chunk {
+ chunk := new(Chunk, allocator);
+ memory.alloc_slice(^chunk.blocks, Chunk_Size * Chunk_Size * Chunk_Size);
+ memory.fill_slice(chunk.blocks, block_make(0.2, 1, 0.2, 1));
+}
+
+#local in_chunk_bounds :: macro (x, y, z: i32) -> bool {
+ if x < 0 do return false;
+ if x >= Chunk_Size do return false;
+ if y < 0 do return false;
+ if y >= Chunk_Size do return false;
+ if z < 0 do return false;
+ if z >= Chunk_Size do return false;
+ return true;
+}
+
+chunk_set :: (use chunk: ^Chunk, x, y, z: i32, block: Block) {
+ if !in_chunk_bounds(x, y, z) do return;
+ blocks[x * Chunk_Size * Chunk_Size + y * Chunk_Size + z] = block;
+}
+
+chunk_get :: (use chunk: ^Chunk, x, y, z: i32) -> Block {
+ if !in_chunk_bounds(x, y, z) do return Block_Empty;
+ return blocks[x * Chunk_Size * Chunk_Size + y * Chunk_Size + z];
+}
+
+chunk_build_mesh :: (use chunk: ^Chunk) -> ^Mesh {
+
+}
create_window :: () => {
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
- window = glfwCreateWindow(800, 600, #cstr "Voxel Shooter");
+ window = glfwCreateWindow(1200, 720, #cstr "Voxel Shooter");
glfwMakeContextCurrent(window);
glfwSwapInterval(0);
}
draw :: () {
- glClearColor(.2, .2, .2, 1);
+ glClearColor(.7, .7, .9, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
#persist forward : Vector3;
Mesh :: struct {
handle: GLuint;
+ vertex_handle: GLuint;
+ index_handle: GLuint;
+
verticies: [] Vertex;
indicies: [] u32;
}
glGenVertexArrays(1, ^mesh.handle);
glBindVertexArray(mesh.handle);
- vbo: GLuint;
- glGenBuffers(1, ^vbo);
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
+ glGenBuffers(1, ^mesh.vertex_handle);
+ glBindBuffer(GL_ARRAY_BUFFER, mesh.vertex_handle);
glBufferData(GL_ARRAY_BUFFER, sizeof Vertex * vertex_data.count, vertex_data.data, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, false, sizeof Vertex, ~~0);
glVertexAttribIPointer(1, 1, GL_UNSIGNED_INT, sizeof Vertex, ~~12);
- ibo: GLuint;
- glGenBuffers(1, ^ibo);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
+ glGenBuffers(1, ^mesh.index_handle);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh.index_handle);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof i32 * 36, ~~index_data, GL_STATIC_DRAW);
glBindVertexArray(-1);
return mesh;
}
+
+mesh_free :: (mesh: ^Mesh) {
+ glDeleteBuffers(1, ^mesh.vertex_handle);
+ glDeleteBuffers(1, ^mesh.index_handle);
+ glDeleteVertexArrays(1, ^mesh.handle);
+}