Question: Question # 1 ( 2 5 points ) : Cube Texture Here are the requirements for the program: Find a suitable cube texture file set

Question #1(25 points): Cube Texture
Here are the requirements for the program:
Find a suitable cube texture file set and copy it to the media folder. Add code to load the cube texture. Use whatever texture unit you wish, but be sure to use it with the artifacts you will create.
The first artifact should be a skybox.
Use a block shape.
Suitably scale and position the artifact.
Set the texture unit appropriately.
Set the surface effect to use the skybox case in the fragment shader.
The second artifact should be a reflection box.
Use a block shape.
Scale the artifact by 1,6, and 1
Center the artifact at -.5,0,3
Set the texture unit appropriately.
Configure rotation animation
The rotation axis should be (0,1,1)
The rotation center should be the center of the artifact.
The rotation rate should be 15 rpm (rotations per minute).
Set the surface effect to use the reflection case in the fragment shader.
Code:
#include
// #include
#include
#include "learnopengl/shader_4722.h"
#include "cs4722/view.h"
#include "cs4722/artifact.h"
#include "cs4722/texture_utilities.h"
#include "cs4722/window.h"
#include "cs4722/buffer_utilities.h"
#include "../callbacks.h"
static cs4722::View *the_view;
static Shader *shader;
static std::vector artifact_list;
void init()
{
the_view = new cs4722::View();
the_view->enableLogging = false;
the_view->setFLUP(glm::vec3(-0.334169,-0.0699426,0.939918),
glm::vec3(0.942223,0,0.334989),
glm::vec3(-0.0234302,0.997553,0.0659021),
glm::vec3(-0.146291,0.195185,1.3214));
shader = new Shader("vertex_shader01.glsl","fragment_shader01.glsl");
shader->use();
glEnable(GL_DEPTH_TEST);
// load in a cube texture hee
// two artifacts go here
cs4722::initBuffers(shader->ID, artifact_list, "b_position", "",
"b_texture_coord", "b_normal");
}
void render()
{
auto view_transform = glm::lookAt(the_view->cameraPosition,
the_view->cameraPosition + the_view->cameraForward,
the_view->cameraUp);
auto projection_transform = glm::infinitePerspective(the_view->perspectiveFOVY,
the_view->perspectiveAspect, the_view->perspectiveNear);
auto vp_transform = projection_transform * view_transform;
shader->setMat4("u_vp_transform", vp_transform);
shader->setVec3("u_camera_position", the_view->cameraPosition);
static auto last_time =0.0;
auto time = glfwGetTime();
auto delta_time = time - last_time;
last_time = time;
for (auto artf : artifact_list){
artf->worldTransformation->animationStep();
glm::mat4 model_transform = artf->worldTransformation->getMatrix();
glm::mat4 n_transform = glm::inverseTranspose(model_transform);
shader->setMat4("u_m_transform", model_transform);
shader->setMat4("u_n_transform", n_transform);
shader->setInt("u_sampler2", artf->textureUnit);
shader->setInt("u_samplerC", artf->textureUnit);
shader->setInt("u_surface_effect", artf->surfaceEffect);
glDrawArrays(GL_TRIANGLES, artf->theShape->bufferStart, artf->theShape->bufferSize);
}
}
int
main(int argc, char** argv)
{
glfwInit();
cs4722::setOpenglVersion(3,3);
GLFWwindow *window = cs4722::setupWindow("Reflecting Object", .5,16.0/9.0);
gladLoadGL(glfwGetProcAddress);
init();
the_view->perspectiveAspect = cs4722::getAspectRatio(window);
glfwSetWindowUserPointer(window, the_view);
printf("view logging %d
", the_view->enableLogging);
glfwSetKeyCallback(window, general_key_callback);
glfwSetCursorPosCallback(window, move_callback);
glfwSetWindowSizeCallback(window, window_size_callback);
while (!glfwWindowShouldClose(window))
{
glClearBufferfv(GL_COLOR, 0, cs4722::X11::gray50.asFloatArray());
glClear(GL_DEPTH_BUFFER_BIT);
render();
glfwSwapBuffers(window);
glfwPollEvents();
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!