diff --git a/shaders/cube_frag.glsl b/shaders/cube_frag.glsl index 3ce0b89..ebcc600 100644 --- a/shaders/cube_frag.glsl +++ b/shaders/cube_frag.glsl @@ -13,10 +13,10 @@ void main() // You can now use v_VoxelKind to modify the color // Example: Different colors for different voxel types vec3 color = u_Color; - if (v_VoxelKind == 0.0) { + if (v_VoxelKind == 1.0) { // Dirt - brownish color *= vec3(0.6, 0.4, 0.2); - } else if (v_VoxelKind == 1.0) { + } else if (v_VoxelKind == 2.0) { // Stone - grayish (keep as is) } diff --git a/src/Chunk.cpp b/src/Chunk.cpp index e22f0e9..6049230 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -119,7 +119,7 @@ void Chunk::generateMesh() { bool neighbour_is_solid = false; // in-bounds neighbor -> check data if (nx >= 0 && nx < SIZE && ny >= 0 && ny < SIZE && nz >= 0 && nz < SIZE) { - std::cout << "Accessing " << nx << ", " << ny << ", " << nz << std::endl; + // std::cout << "Accessing " << nx << ", " << ny << ", " << nz << std::endl; neighbour_is_solid = (data[index(nx, ny, nz)] != VoxelKind::Air); } else { // neighbour out of this chunk: treat as air (exposed face) diff --git a/src/Chunk.h b/src/Chunk.h index 886cca9..5948e76 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -52,7 +52,7 @@ class Chunk { return data[index(x, y, z)]; } inline VoxelKind get(glm::ivec3 pos) const { - std::cout << "Getting Pos (" << pos.x << ", " << pos.y << ", " << pos.z << ")" << std::endl; + // std::cout << "Getting Pos (" << pos.x << ", " << pos.y << ", " << pos.z << ")" << std::endl; return data[index(pos.x, pos.y, pos.z)]; } diff --git a/src/World.cpp b/src/World.cpp index 47402b0..3939eee 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -169,5 +169,5 @@ VoxelKind World::get_voxel(glm::ivec3 position) { Chunk* chunk = this->get_or_create_chunk(chunk_position); - return chunk->get(position); + return chunk->get(local_position); } diff --git a/src/main.cpp b/src/main.cpp index ad335d5..c09cfdc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,6 +30,8 @@ const float Z_NEAR = 0.1f; bool WIREFRAME_MODE = !true; const float FOV = 110.0f; +const std::string VERSION = "0.8.0"; + const int VIEW_DISTANCE = 4; // In Chunks bool W_pressed, S_pressed, A_pressed, D_pressed = false; @@ -269,7 +271,7 @@ int main() { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 2. --- Create a Window --- - GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "Voxel Engine 0.7.0", NULL, NULL); + GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, ("Voxel Engine " + VERSION).c_str(), NULL, NULL); if (window == NULL) { std::cerr << "Failed to create GLFW window" << std::endl; glfwTerminate(); @@ -391,8 +393,24 @@ int main() { glEnable(GL_DEPTH_TEST); bool debug_printed = false; + // FPS counter variables + double last_fps_update = glfwGetTime(); + int frame_count = 0; + double fps = 0.0; + // 6. --- The Render Loop --- while (!glfwWindowShouldClose(window)) { + // Update FPS counter + double current_time = glfwGetTime(); + frame_count++; + if (current_time - last_fps_update >= 1.0) { + fps = frame_count / (current_time - last_fps_update); + std::string title = "Voxel Engine " + VERSION + " | FPS: " + std::to_string((int)fps); + glfwSetWindowTitle(window, title.c_str()); + frame_count = 0; + last_fps_update = current_time; + } + // Input (e.g., close window on ESC) processInput(window); @@ -403,13 +421,6 @@ int main() { shader.use(); - // if (!debug_printed) { - // std::cout << "\n=== RENDER DEBUG ===" << std::endl; - // std::cout << "Camera pos: (" << camera.position.x << ", " << camera.position.y << ", " << camera.position.z << ")" << std::endl; - // std::cout << "Camera target: (" << camera.target.x << ", " << camera.target.y << ", " << camera.target.z << ")" << std::endl; - // // std::cout << "Number of chunks to draw: " << world.chunks.size() << std::endl; - // } - // Generate chunks around the camera glm::ivec3 camera_chunk = glm::ivec3( std::floor(camera.position.x / CHUNK_SIZE), @@ -437,6 +448,8 @@ int main() { Chunk* chunk = world.get_or_create_chunk(chunk_pos); Mesh* chunk_mesh = chunk->getMesh(); + if (chunk_mesh) + chunk_mesh->draw(); } } }