Question: How would I change my code to get the picture below? #include GLM/gtc/type_ptr.hpp #include #include learnopengl/shader.h #include cs4722/artifact.h static std::vector artifact_list; static GLuint program; //
How would I change my code to get the picture below?
#include "GLM/gtc/type_ptr.hpp" #include#include "learnopengl/shader.h" #include "cs4722/artifact.h" static std::vector<:artifact> artifact_list; static GLuint program; // locations of variables in the shaders const static auto u_transform = 1; const static auto b_position = 1; const static auto b_color = 2; const unsigned int color_loc = 1; auto offset1 = 30; auto bOffset1 = 0; auto const verts_per_triangle = 3; auto size2 = 4 * 4 * verts_per_triangle; auto offset2 = offset1 + verts_per_triangle; auto bOffset2 = bOffset1 + size2; auto color2 = cs4722::x11::goldenrod1; void init(void) { Shader shader("01-more-shapes/vertex_shader.glsl" ,"01-more-shapes/fragment_shader.glsl" ); program = shader.ID; glUseProgram(program); glEnable(GL_PROGRAM_POINT_SIZE); glEnable(GL_DEPTH_TEST); //cs4722::shape* b = new cs4722::torus(.5, 20,50); cs4722::shape* b = new cs4722::rectangle(1,1); auto* artf = new cs4722::artifact(); artf->the_shape = b; artf->world_transform.translate = glm::vec3(-.5, -.5, 0); artf->world_transform.scale = glm::vec3(.2f, .5f, .4f); artf->world_transform.matrix() = glm::rotate(glm::mat4(1.0f), glm::radians(30.0f), glm::vec3(0.0f, 0.0f, 1.0f)); //glm::mat4 trans = glm::rotate(glm::mat4(1.0f), glm::radians(30.0f), glm::vec3(0.0f, 0.0f, 1.0f)); artifact_list.push_back(artf); cs4722::shape* c = new cs4722::rectangle(10,10); auto* artfa = new cs4722::artifact(); artfa->the_shape = c; artfa->world_transform.translate = glm::vec3(1, -1, 0); artfa->world_transform.scale = glm::vec3(.6f, .8f, .5f); artifact_list.push_back(artfa); glm::vec4 positions2[] = { glm::vec4(.25, -.75, .3, 1), glm::vec4(.2, -.8,0, 1), glm::vec4(.8, -.8, 0, 1) }; /* * Set up buffers */ auto total_vertex_count = 0; for(auto *artf : artifact_list) { if(artf->the_shape->buffer_size == 0) { artf->the_shape->buffer_start = total_vertex_count; artf->the_shape->buffer_size = artf->the_shape->get_size(); total_vertex_count += artf->the_shape->get_size(); } else { artf->shape_is_shared = true; } } GLuint vao; glGenVertexArrays(1, &vao); glBindVertexArray(vao); const int number_of_buffers = 2; GLuint buffers[number_of_buffers]; glGenBuffers(number_of_buffers, buffers); glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); glBufferData(GL_ARRAY_BUFFER, 4 * 4 * total_vertex_count, NULL, GL_STATIC_DRAW); glVertexAttribPointer(b_position, 4, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(b_position); glBindBuffer(GL_ARRAY_BUFFER, buffers[1]); glBufferData(GL_ARRAY_BUFFER, 4 * 1 * total_vertex_count, NULL, GL_STATIC_DRAW); glVertexAttribPointer(b_color, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0); glEnableVertexAttribArray(b_color); glBufferSubData(GL_ARRAY_BUFFER, bOffset2, size2, positions2); for (auto artf : artifact_list) { if(!artf->shape_is_shared) { auto pos = artf->the_shape->positions(); glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); glBufferSubData(GL_ARRAY_BUFFER, 4 * 4 * artf->the_shape->buffer_start, 4 * 4 * artf->the_shape->buffer_size, pos->data()); delete pos; auto colors = artf->the_shape->colors(); glBindBuffer(GL_ARRAY_BUFFER, buffers[1]); glBufferSubData(GL_ARRAY_BUFFER, 4 * 1 * artf->the_shape->buffer_start, 4 * 1 * artf->the_shape->buffer_size, colors->data()); delete colors; } } } void render() { //glUniform4fv(color_loc, 1, color2.as_float().get()); //glDrawArrays(GL_TRIANGLES, offset2, verts_per_triangle); for (auto artf : artifact_list) { auto model_matrix = artf->animation_transform.matrix() * artf->world_transform.matrix(); glUniformMatrix4fv(u_transform, 1, GL_FALSE, glm::value_ptr(model_matrix)); glDrawArrays(GL_TRIANGLES, artf->the_shape->buffer_start, artf->the_shape->buffer_size); // glRotatef(60.0, 1.0, 1.0, 1.0); break; } } int main(int argc, char** argv) { glfwInit(); // set the OpenGL version to use: 3.3 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); GLFWmonitor* primary = glfwGetPrimaryMonitor(); int xpos, ypos, width, height; glfwGetMonitorWorkarea(primary, &xpos, &ypos, &width, &height); //std::cout
Transcribed image text
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock

