Fixed brick code which caused memory override for mesh data and fucked up rendering
This commit is contained in:
@@ -24,9 +24,10 @@ int main() {
|
|||||||
|
|
||||||
acidrain::texture_generator tg(256, 256);
|
acidrain::texture_generator tg(256, 256);
|
||||||
tg.brick(0, 50, 20, 4, glm::vec4(1), glm::vec4(0));
|
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<mesh> affectedSphere = mesh_generator::sphere(50, 50);
|
shared_ptr<mesh> 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());
|
calculate_normals(*affectedSphere.get());
|
||||||
|
|
||||||
// affectedSphere = mesh_generator::cog(0.2, 0.5, 50, 4, 0.1, 0.2, 0.2, 0.1);
|
// 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<mesh_node>("light mesh");
|
auto lightMeshNode = std::make_shared<mesh_node>("light mesh");
|
||||||
lightMeshNode->mesh_ = demo_data::meshes[0];
|
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->position = glm::vec3(1, 2, 1);
|
||||||
lightMeshNode->scale = glm::vec3(0.1);
|
lightMeshNode->scale = glm::vec3(0.5);
|
||||||
|
|
||||||
auto camNode = std::make_shared<camera_node>();
|
auto camNode = std::make_shared<camera_node>();
|
||||||
camNode->name = "cam1";
|
camNode->name = "cam1";
|
||||||
@@ -210,7 +211,6 @@ int main() {
|
|||||||
timer timer1;
|
timer timer1;
|
||||||
while (!peripherals.should_close() && timer1.seconds_since_start() < DEMO_LENGTH_IN_SECONDS) {
|
while (!peripherals.should_close() && timer1.seconds_since_start() < DEMO_LENGTH_IN_SECONDS) {
|
||||||
double elapsedSeconds = timer1.seconds_since_start();
|
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,
|
bigSphere->mesh_ = mesh_generator::extrude(mesh_generator::sphere(50, 50), {200, 201, 100, 101, 400, 401}, 0.05,
|
||||||
(int) ((sin(elapsedSeconds) + 0.5) * 40));
|
(int) ((sin(elapsedSeconds) + 0.5) * 40));
|
||||||
|
|
||||||
@@ -218,8 +218,8 @@ int main() {
|
|||||||
// meshNode->position = glm::vec3(0, 0.001, 0);
|
// meshNode->position = glm::vec3(0, 0.001, 0);
|
||||||
// camNode->target = glm::vec3(0, 0.0001, 0);
|
// camNode->target = glm::vec3(0, 0.0001, 0);
|
||||||
// camNode->position = glm::vec3(0, 5, -10);
|
// camNode->position = glm::vec3(0, 5, -10);
|
||||||
lightNode2->position = glm::vec3(5 * sin(2 * M_PI * 0.15 * elapsedSeconds), 2,
|
lightNode2->position = glm::vec3(5 * sin(2 * M_PI * 0.05 * elapsedSeconds), 2,
|
||||||
5 * cos(2 * M_PI * 0.15 * elapsedSeconds));
|
5 * cos(2 * M_PI * 0.05 * elapsedSeconds));
|
||||||
lightNode->position = glm::vec3(5 * cos(2 * M_PI * 0.75 * elapsedSeconds), 2,
|
lightNode->position = glm::vec3(5 * cos(2 * M_PI * 0.75 * elapsedSeconds), 2,
|
||||||
5 * sin(2 * M_PI * 0.75 * elapsedSeconds));
|
5 * sin(2 * M_PI * 0.75 * elapsedSeconds));
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ BEGIN_NAMESPACE
|
|||||||
|
|
||||||
// fill in buffer
|
// fill in buffer
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
size_t face_index = 0;
|
||||||
for (auto& f: facets) {
|
for (auto& f: facets) {
|
||||||
for (int j = 0; j < 3; j++) {
|
for (int j = 0; j < 3; j++) {
|
||||||
vbo_data[i++] = vertices[f.vertices[j]].position.x;
|
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].x;
|
||||||
vbo_data[i++] = f.text_coords[j].y;
|
vbo_data[i++] = f.text_coords[j].y;
|
||||||
}
|
}
|
||||||
|
face_index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
glBindVertexArray(vao_id);
|
glBindVertexArray(vao_id);
|
||||||
|
|||||||
@@ -6,15 +6,15 @@
|
|||||||
|
|
||||||
BEGIN_NAMESPACE
|
BEGIN_NAMESPACE
|
||||||
|
|
||||||
static void error_callback(int error, const char* description) {
|
static void error_callback(int error, const char *description) {
|
||||||
LOG(ERROR) << "glfw error callback: " << error << ", " << description;
|
LOG(ERROR) << "glfw error callback: " << error << ", " << description;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void window_size_callback(GLFWwindow* window, int width, int height) {
|
static void window_size_callback(GLFWwindow *window, int width, int height) {
|
||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
|
static void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods) {
|
||||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
|
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
|
||||||
glfwSetWindowShouldClose(window, true);
|
glfwSetWindowShouldClose(window, true);
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,13 @@ bool peripherals_glfw::init() {
|
|||||||
|
|
||||||
glfwSetErrorCallback(error_callback);
|
glfwSetErrorCallback(error_callback);
|
||||||
|
|
||||||
window = glfwCreateWindow(demo_data::screen_width, demo_data::screen_height, "Demo", nullptr, nullptr);
|
|
||||||
|
bool fullscreen = false;
|
||||||
|
window = glfwCreateWindow(demo_data::screen_width,
|
||||||
|
demo_data::screen_height,
|
||||||
|
"Demo",
|
||||||
|
fullscreen ? glfwGetPrimaryMonitor() : nullptr,
|
||||||
|
nullptr);
|
||||||
if (window == nullptr) {
|
if (window == nullptr) {
|
||||||
LOG(FATAL) << "unable to create window!";
|
LOG(FATAL) << "unable to create window!";
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -366,7 +366,6 @@ std::shared_ptr<scene_node> camNode = tree.node_by_name_and_type(cameraName, sce
|
|||||||
for (auto &node: tree.nodes) {
|
for (auto &node: tree.nodes) {
|
||||||
if (node->type == scene_node_type::mesh) {
|
if (node->type == scene_node_type::mesh) {
|
||||||
mesh_node &meshNode = node->as_mesh_node();
|
mesh_node &meshNode = node->as_mesh_node();
|
||||||
LOG(INFO) << "rendering mesh node " << meshNode.name;
|
|
||||||
|
|
||||||
glm::mat3 normalMatrix = glm::inverseTranspose(
|
glm::mat3 normalMatrix = glm::inverseTranspose(
|
||||||
glm::mat3(camera.view_matrix * meshNode.model_to_world_space_matrix));
|
glm::mat3(camera.view_matrix * meshNode.model_to_world_space_matrix));
|
||||||
|
|||||||
@@ -214,10 +214,10 @@ texture_generator &texture_generator::brick(uint8_t layer,
|
|||||||
int x = is_odd_row ? 0 : brick_width / 2;
|
int x = is_odd_row ? 0 : brick_width / 2;
|
||||||
while (x < width) {
|
while (x < width) {
|
||||||
for (int i = 0; i < gap_size; i++) {
|
for (int i = 0; i < gap_size; i++) {
|
||||||
for (int current_brick_y = 0; current_brick_y < (brick_height - 1); current_brick_y++) {
|
for (int current_brick_y = 0; current_brick_y < brick_height; current_brick_y++) {
|
||||||
// if ((current_brick_y + y) < height) {
|
if ((current_brick_y + y) < height) {
|
||||||
input[x + i + (current_brick_y + y) * width] = mortar_color;
|
input[x + i + (current_brick_y + y) * width] = mortar_color;
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user