Fixed brick code which caused memory override for mesh data and fucked up rendering
This commit is contained in:
@@ -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);
|
||||
|
||||
+43
-37
@@ -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
|
||||
@@ -366,7 +366,6 @@ std::shared_ptr<scene_node> 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));
|
||||
|
||||
@@ -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;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user