create_window :: () => {
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
window = glfwCreateWindow(800, 600, #cstr "Voxel Shooter");
glfwMakeContextCurrent(window);
- glfwSwapInterval(1);
+ glfwSwapInterval(0);
glfwSetWindowSizeCallback(window, "on_resize");
glfwSetKeyCallback(window, "on_key");
}
glEnable(GL_CULL_FACE);
glFrontFace(GL_CW);
glCullFace(GL_BACK);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
compile_shader :: (source: str, type: GLenum) -> GLint {
shader := glCreateShader(type);
matrix_block_index := glGetUniformBlockIndex(prog, #cstr "u_matrix_block");
glUniformBlockBinding(prog, matrix_block_index, 0);
- for 100 {
- x := random.between(0, 10);
- y := random.between(0, 10);
- z := random.between(0, 10);
+ for 1000 {
+ x := random.between(0, 31);
+ y := random.between(0, 31);
+ z := random.between(0, 31);
cubes << mesh_make_cube(~~x, ~~y, ~~z);
}
camera.x_rot += ~~(my - last_mouse_y) / 400.0f;
camera.x_rot = math.clamp(camera.x_rot, -math.PI / 2 + 0.1, math.PI / 2 - 0.1);
+ speed := 3 * dt;
+ if glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS {
+ speed = 8 * dt;
+ }
+
facing := camera_get_forward(^camera);
if glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS {
- camera.position += facing * 3 * dt;
+ camera.position += facing * speed;
}
if glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS {
- camera.position -= facing * 3 * dt;
+ camera.position -= facing * speed;
}
if glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS {
- camera.position += Vector3.norm(Vector3.cross(facing, .{0,1,0})) * 3 * dt;
+ camera.position += Vector3.norm(Vector3.cross(facing, .{0,1,0})) * speed;
}
if glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS {
- camera.position -= Vector3.norm(Vector3.cross(facing, .{0,1,0})) * 3 * dt;
+ camera.position -= Vector3.norm(Vector3.cross(facing, .{0,1,0})) * speed;
}
update_world_matrix();
glClearColor(.2, .2, .2, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- // mesh_draw(^plane_mesh);
- //mesh_draw(^cube_mesh);
- for^ cubes do mesh_draw(it);
+ #persist forward : Vector3;
+ forward = camera_get_forward(^camera);
+ array.sort(cubes, (x, y) => {
+ v := Vector3.dot(forward, *(cast(^Vector3) ^y.verticies[0]) - camera.position) - Vector3.dot(forward, *(cast(^Vector3) ^x.verticies[0]) - camera.position);
+ if v < 0 do return -1;
+ if v > 0 do return 1;
+ return 0;
+ });
+
+ for^ cubes {
+ if Vector3.dot(forward, *(cast(^Vector3) ^it.verticies[0]) - camera.position) < 0 do continue;
+ mesh_draw(it);
+ }
glfwSwapBuffers(window);
}