diff --git a/main.cpp b/main.cpp index dedb276..b557941 100644 --- a/main.cpp +++ b/main.cpp @@ -24,9 +24,10 @@ int main() { acidrain::texture_generator tg(256, 256); tg.brick(0, 50, 20, 4, glm::vec4(1), glm::vec4(0)); +// tg.checker_board(0, 50, glm::vec4(1), glm::vec4(0)); shared_ptr affectedSphere = mesh_generator::sphere(50, 50); - map_transform(affectedSphere, tg, 0, 0, 1.2f); + map_transform(affectedSphere, tg, 0, 0, 0.2f); calculate_normals(*affectedSphere.get()); // affectedSphere = mesh_generator::cog(0.2, 0.5, 50, 4, 0.1, 0.2, 0.2, 0.1); @@ -156,9 +157,9 @@ int main() { auto lightMeshNode = std::make_shared("light mesh"); lightMeshNode->mesh_ = demo_data::meshes[0]; - lightMeshNode->material_ = demo_data::materials[3]; + lightMeshNode->material_ = demo_data::materials[0]; lightMeshNode->position = glm::vec3(1, 2, 1); - lightMeshNode->scale = glm::vec3(0.1); + lightMeshNode->scale = glm::vec3(0.5); auto camNode = std::make_shared(); camNode->name = "cam1"; @@ -210,7 +211,6 @@ int main() { timer timer1; while (!peripherals.should_close() && timer1.seconds_since_start() < DEMO_LENGTH_IN_SECONDS) { double elapsedSeconds = timer1.seconds_since_start(); - LOG(INFO) << "frame start"; bigSphere->mesh_ = mesh_generator::extrude(mesh_generator::sphere(50, 50), {200, 201, 100, 101, 400, 401}, 0.05, (int) ((sin(elapsedSeconds) + 0.5) * 40)); @@ -218,8 +218,8 @@ int main() { // meshNode->position = glm::vec3(0, 0.001, 0); // camNode->target = glm::vec3(0, 0.0001, 0); // camNode->position = glm::vec3(0, 5, -10); - lightNode2->position = glm::vec3(5 * sin(2 * M_PI * 0.15 * elapsedSeconds), 2, - 5 * cos(2 * M_PI * 0.15 * elapsedSeconds)); + lightNode2->position = glm::vec3(5 * sin(2 * M_PI * 0.05 * elapsedSeconds), 2, + 5 * cos(2 * M_PI * 0.05 * elapsedSeconds)); lightNode->position = glm::vec3(5 * cos(2 * M_PI * 0.75 * elapsedSeconds), 2, 5 * sin(2 * M_PI * 0.75 * elapsedSeconds)); diff --git a/src/mesh.cpp b/src/mesh.cpp index d8ffa14..e8ba9b4 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -42,6 +42,7 @@ BEGIN_NAMESPACE // fill in buffer size_t i = 0; + size_t face_index = 0; for (auto& f: facets) { for (int j = 0; j < 3; j++) { vbo_data[i++] = vertices[f.vertices[j]].position.x; @@ -59,6 +60,7 @@ BEGIN_NAMESPACE vbo_data[i++] = f.text_coords[j].x; vbo_data[i++] = f.text_coords[j].y; } + face_index++; } glBindVertexArray(vao_id); diff --git a/src/peripherals_glfw.cpp b/src/peripherals_glfw.cpp index a517cc5..8c3688d 100644 --- a/src/peripherals_glfw.cpp +++ b/src/peripherals_glfw.cpp @@ -6,64 +6,70 @@ BEGIN_NAMESPACE -static void error_callback(int error, const char* description) { - LOG(ERROR) << "glfw error callback: " << error << ", " << description; +static void error_callback(int error, const char *description) { + LOG(ERROR) << "glfw error callback: " << error << ", " << description; } -static void window_size_callback(GLFWwindow* window, int width, int height) { - glViewport(0, 0, width, height); +static void window_size_callback(GLFWwindow *window, int width, int height) { + glViewport(0, 0, width, height); } -static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { - if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) { - glfwSetWindowShouldClose(window, true); - } +static void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods) { + if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) { + glfwSetWindowShouldClose(window, true); + } } bool peripherals_glfw::init() { - glfwInit(); - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); - glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); - glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); + glfwInit(); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); - glfwSetErrorCallback(error_callback); + glfwSetErrorCallback(error_callback); - window = glfwCreateWindow(demo_data::screen_width, demo_data::screen_height, "Demo", nullptr, nullptr); - if (window == nullptr) { - LOG(FATAL) << "unable to create window!"; - return false; - } - glfwMakeContextCurrent(window); - if (window == nullptr) { - LOG(FATAL) << "unable to make opengl context current!"; - return false; - } + bool fullscreen = false; + window = glfwCreateWindow(demo_data::screen_width, + demo_data::screen_height, + "Demo", + fullscreen ? glfwGetPrimaryMonitor() : nullptr, + nullptr); + if (window == nullptr) { + LOG(FATAL) << "unable to create window!"; + return false; + } - glfwSetKeyCallback(window, key_callback); - glfwSetWindowSizeCallback(window, window_size_callback); + glfwMakeContextCurrent(window); + if (window == nullptr) { + LOG(FATAL) << "unable to make opengl context current!"; + return false; + } - if (!gladLoadGL()) { - LOG(FATAL) << "unable to load opengl functions!"; - return false; - } else { - LOG(INFO) << "created window and loaded opengl"; - } - return true; + glfwSetKeyCallback(window, key_callback); + glfwSetWindowSizeCallback(window, window_size_callback); + + if (!gladLoadGL()) { + LOG(FATAL) << "unable to load opengl functions!"; + return false; + } else { + LOG(INFO) << "created window and loaded opengl"; + } + return true; } void peripherals_glfw::swap_buffers() { - glfwSwapBuffers(window); + glfwSwapBuffers(window); } void peripherals_glfw::poll_events() { - glfwPollEvents(); + glfwPollEvents(); }; bool peripherals_glfw::should_close() { - return glfwWindowShouldClose(window); + return glfwWindowShouldClose(window); } END_NAMESPACE \ No newline at end of file diff --git a/src/scene_renderer.cpp b/src/scene_renderer.cpp index abe4da8..2b48e99 100644 --- a/src/scene_renderer.cpp +++ b/src/scene_renderer.cpp @@ -366,7 +366,6 @@ std::shared_ptr camNode = tree.node_by_name_and_type(cameraName, sce for (auto &node: tree.nodes) { if (node->type == scene_node_type::mesh) { mesh_node &meshNode = node->as_mesh_node(); - LOG(INFO) << "rendering mesh node " << meshNode.name; glm::mat3 normalMatrix = glm::inverseTranspose( glm::mat3(camera.view_matrix * meshNode.model_to_world_space_matrix)); diff --git a/src/texture_generator.cpp b/src/texture_generator.cpp index 450f20d..6b7fc6a 100644 --- a/src/texture_generator.cpp +++ b/src/texture_generator.cpp @@ -214,10 +214,10 @@ texture_generator &texture_generator::brick(uint8_t layer, int x = is_odd_row ? 0 : brick_width / 2; while (x < width) { for (int i = 0; i < gap_size; i++) { - for (int current_brick_y = 0; current_brick_y < (brick_height - 1); current_brick_y++) { -// if ((current_brick_y + y) < height) { + for (int current_brick_y = 0; current_brick_y < brick_height; current_brick_y++) { + if ((current_brick_y + y) < height) { input[x + i + (current_brick_y + y) * width] = mortar_color; -// } + } } }