bool load_content() { geom.set_type(GL_TRIANGLE_STRIP); // Create quad data // Positions vector<vec3> positions{vec3(-1.0f, -1.0f, 0.0f), vec3(1.0f, -1.0f, 0.0f), vec3(-1.0f, 1.0f, 0.0f), vec3(1.0f, 1.0f, 0.0f)}; // Colours vector<vec4> colours{vec4(1.0f, 0.0f, 0.0f, 1.0f), vec4(1.0f, 0.0f, 0.0f, 1.0f), vec4(1.0f, 0.0f, 0.0f, 1.0f), vec4(1.0f, 0.0f, 0.0f, 1.0f)}; // Add to the geometry geom.add_buffer(positions, BUFFER_INDEXES::POSITION_BUFFER); geom.add_buffer(colours, BUFFER_INDEXES::COLOUR_BUFFER); // Load in shaders eff.add_shader("shaders/basic.vert", GL_VERTEX_SHADER); eff.add_shader("shaders/basic.frag", GL_FRAGMENT_SHADER); // Build effect eff.build(); // Set camera properties cam.set_position(vec3(10.0f, 10.0f, 10.0f)); cam.set_target(vec3(0.0f, 0.0f, 0.0f)); auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height()); cam.set_projection(quarter_pi<float>(), aspect, 2.414f, 1000.0f); return true; }
bool load_content() { // Create mesh object, cheating and using the mesh builder for now m = mesh(geometry_builder::create_box()); // Scale geometry m.get_transform().scale = vec3(10.0f); // Load in dissolve shader eff.add_shader("33_Dissolve/dissolve.vert", GL_VERTEX_SHADER); eff.add_shader("33_Dissolve/dissolve.frag", GL_FRAGMENT_SHADER); // Build effect eff.build(); // Load in textures tex = texture("textures/checker.png"); dissolve = texture("textures/blend_map2.jpg"); // Set camera properties cam.set_position(vec3(30.0f, 30.0f, 30.0f)); cam.set_target(vec3(0.0f, 0.0f, 0.0f)); auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height()); cam.set_projection(quarter_pi<float>(), aspect, 2.414f, 1000.0f); return true; }
bool load_content() { // ************* // Load in model // ************* m = mesh(geometry("..\\resources\\models\\teapot.obj")); // *************** // Load in texture // *************** tex = texture("..\\resources\\textures\\checked.gif", false, false); // Load in shaders eff.add_shader("..\\resources\\shaders\\simple_texture.vert", GL_VERTEX_SHADER); eff.add_shader("..\\resources\\shaders\\simple_texture.frag", GL_FRAGMENT_SHADER); // Build effect eff.build(); // Set camera properties cam.set_position(vec3(200.0f, 200.0f, 200.0f)); cam.set_target(vec3(0.0f, 0.0f, 0.0f)); auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height()); cam.set_projection(quarter_pi<float>(), aspect, 2.414f, 1000.0f); return true; }
bool load_content() { // ********************************* // Create shadow map- use screen size shadow = shadow_map(renderer::get_screen_width(), renderer::get_screen_height()); // Create plane mesh meshes["plane"] = mesh(geometry_builder::create_plane()); // Create "teapot" mesh by loading in models/teapot.obj meshes["teapot"] = mesh(geometry("models/teapot.obj")); // Need to rotate the teapot on x by negative pi/2 meshes["teapot"].get_transform().rotate(vec3(-90.0, 0.0, 0.0)); // Scale the teapot - (0.1, 0.1, 0.1) meshes["teapot"].get_transform().scale = vec3(0.1,0.1,0.1); // *********************** // Set materials // - all emissive is black // - all specular is white // - all shininess is 25 // *********************** // White plane meshes["plane"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f)); meshes["plane"].get_material().set_diffuse(vec4(1.0f, 1.0f, 1.0f, 1.0f)); meshes["plane"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); meshes["plane"].get_material().set_shininess(25.0f); // Red teapot meshes["teapot"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f)); meshes["teapot"].get_material().set_diffuse(vec4(1.0f, 0.0f, 0.0f, 1.0f)); meshes["teapot"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); meshes["teapot"].get_material().set_shininess(25.0f); // ********************************* // Set spot properties // Pos (20, 30, 0), White // Direction (-1, -1, 0) normalized // 50 range, 10 power spot.set_position(vec3(20.0f, 30.0f, 0.0f)); spot.set_light_colour(vec4(1.0f, 1.0f, 1.0f, 1.0f)); spot.set_direction(normalize(vec3(-1.0f, -1.0f, 0.0f))); spot.set_range(50.0f); spot.set_power(10.0f); // Load in shaders shadow_eff.add_shader("50_Spot_Light/spot.vert", GL_VERTEX_SHADER); shadow_eff.add_shader("50_Spot_Light/spot.frag", GL_FRAGMENT_SHADER); // Build effect shadow_eff.build(); // Set camera properties cam.set_position(vec3(0.0f, 20.0f, -30.0f)); cam.set_target(vec3(0.0f, 0.0f, 0.0f)); cam.set_projection(quarter_pi<float>(), renderer::get_screen_aspect(), 0.1f, 1000.0f); return true; }
bool load_content() { // Create cube data - eight corners // Positions vector<vec3> positions{ // ********************************* // Add the position data for cube corners here (8 total) // ********************************* }; // Colours vector<vec4> colours; for (auto i = 0; i < positions.size(); ++i) { colours.push_back(vec4((i + 1) % 2, 0.0f, i % 2, 1.0f)); } // Create the index buffer vector<GLuint> indices{ // ********************************* // Add index information here - 3 per triangle, 6 per face, 12 triangles // Front // Back // Right // Left // Top // Bottom // ********************************* }; // Add to the geometry geom.add_buffer(positions, BUFFER_INDEXES::POSITION_BUFFER); geom.add_buffer(colours, BUFFER_INDEXES::COLOUR_BUFFER); // **************************** // Add index buffer to geometry // **************************** geom.add_index_buffer(indices); // Load in shaders eff.add_shader("shaders/basic.vert", GL_VERTEX_SHADER); eff.add_shader("shaders/basic.frag", GL_FRAGMENT_SHADER); // Build effect eff.build(); // Set camera properties cam.set_position(vec3(10.0f, 10.0f, 10.0f)); cam.set_target(vec3(0.0f, 0.0f, 0.0f)); auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height()); cam.set_projection(quarter_pi<float>(), aspect, 2.414f, 1000.0f); return true; }
bool load_content() { // ************************** // Set geometry type to quads // ************************** geom.set_type(GL_QUADS); // Create quad data // Positions vector<vec3> positions { // *********************************************** // Add the four positions of the quad corners here // *********************************************** vec3(-1.0f, 1.0f, 0.0f), vec3(-1.0f, -1.0f, 0.0f), vec3(1.0f, -1.0f, 0.0f), vec3(1.0f, 1.0f, 0.0f) }; // Colours vector<vec4> colours { vec4(1.0f, 0.0f, 0.0f, 1.0f), vec4(1.0f, 0.0f, 0.0f, 1.0f), vec4(1.0f, 0.0f, 0.0f, 1.0f), vec4(1.0f, 0.0f, 0.0f, 1.0f) }; // Add to the geometry geom.add_buffer(positions, BUFFER_INDEXES::POSITION_BUFFER); geom.add_buffer(colours, BUFFER_INDEXES::COLOUR_BUFFER); // Load in shaders eff.add_shader( "..\\resources\\shaders\\basic.vert", // filename GL_VERTEX_SHADER); // type eff.add_shader( "..\\resources\\shaders\\basic.frag", // filename GL_FRAGMENT_SHADER); // type // Build effect eff.build(); // Set camera properties cam.set_position(vec3(10.0f, 10.0f, 10.0f)); cam.set_target(vec3(0.0f, 0.0f, 0.0f)); auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height()); cam.set_projection(quarter_pi<float>(), aspect, 2.414f, 1000.0f); return true; }
bool load_content() { // Construct geometry object geometry geom; // Create triangle data // Positions vector<vec3> positions{vec3(0.0f, 1.0f, 0.0f), vec3(-1.0f, -1.0f, 0.0f), vec3(1.0f, -1.0f, 0.0f)}; // ********************************* // Define texture coordinates for triangle vector<vec2> UVs{ vec2(0.0f, 1.0f), vec2(-1.0f, -1.0f), vec2(1.0f, -1.0f) }; // ********************************* // Add to the geometry geom.add_buffer(positions, BUFFER_INDEXES::POSITION_BUFFER); // ********************************* // Add texture coordinate buffer to geometry geom.add_buffer(positions, BUFFER_INDEXES::TEXTURE_COORDS_0); // ********************************* // Create mesh object m = mesh(geom); m2 = mesh(geom); m2.get_transform().translate(vec3(5.0f, 1.0f, 1.0f)); // Load in texture shaders here eff.add_shader("27_Texturing_Shader/simple_texture.vert", GL_VERTEX_SHADER); eff.add_shader("27_Texturing_Shader/simple_texture.frag", GL_FRAGMENT_SHADER); // ********************************* // Build effect eff.build(); // Load texture "textures/sign.jpg" tex = texture("textures/sign.jpg"); tex2 = texture("textures/stonygrass.jpg"); // ********************************* // Set camera properties cam.set_position(vec3(10.0f, 10.0f, 10.0f)); cam.set_target(vec3(0.0f, 0.0f, 0.0f)); auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height()); cam.set_projection(quarter_pi<float>(), aspect, 2.414f, 1000.0f); return true; }
bool load_content() { // Create plane mesh meshes["plane"] = mesh(geometry_builder::create_plane()); // Create scene meshes["box"] = mesh(geometry_builder::create_box()); meshes["tetra"] = mesh(geometry_builder::create_tetrahedron()); meshes["pyramid"] = mesh(geometry_builder::create_pyramid()); meshes["disk"] = mesh(geometry_builder::create_disk(20)); meshes["cylinder"] = mesh(geometry_builder::create_cylinder(20, 20)); meshes["sphere"] = mesh(geometry_builder::create_sphere(20, 20)); meshes["torus"] = mesh(geometry_builder::create_torus(20, 20, 1.0f, 5.0f)); // Transform objects meshes["box"].get_transform().scale = vec3(5.0f, 5.0f, 5.0f); meshes["box"].get_transform().translate(vec3(-10.0f, 2.5f, -30.0f)); meshes["tetra"].get_transform().scale = vec3(4.0f, 4.0f, 4.0f); meshes["tetra"].get_transform().translate(vec3(-30.0f, 10.0f, -10.0f)); meshes["pyramid"].get_transform().scale = vec3(5.0f, 5.0f, 5.0f); meshes["pyramid"].get_transform().translate(vec3(-10.0f, 7.5f, -30.0f)); meshes["disk"].get_transform().scale = vec3(3.0f, 1.0f, 3.0f); meshes["disk"].get_transform().translate(vec3(-10.0f, 11.5f, -30.0f)); meshes["disk"].get_transform().rotate(vec3(half_pi<float>(), 0.0f, 0.0f)); meshes["cylinder"].get_transform().scale = vec3(5.0f, 5.0f, 5.0f); meshes["cylinder"].get_transform().translate(vec3(-25.0f, 2.5f, -25.0f)); meshes["sphere"].get_transform().scale = vec3(2.5f, 2.5f, 2.5f); meshes["sphere"].get_transform().translate(vec3(-25.0f, 10.0f, -25.0f)); meshes["torus"].get_transform().translate(vec3(-25.0f, 10.0f, -25.0f)); meshes["torus"].get_transform().rotate(vec3(half_pi<float>(), 0.0f, 0.0f)); // Load texture tex = texture("textures/checker.png"); // Load in shaders eff.add_shader("27_Texturing_Shader/simple_texture.vert", GL_VERTEX_SHADER); eff.add_shader("27_Texturing_Shader/simple_texture.frag", GL_FRAGMENT_SHADER); // Build effect eff.build(); // Set camera properties cam.set_position(vec3(50.0f, 10.0f, 50.0f)); cam.set_target(vec3(0.0f, 0.0f, 0.0f)); cam.set_projection(quarter_pi<float>(), renderer::get_screen_aspect(), 0.1f, 1000.0f); return true; }
bool load_content() { // Construct geometry object geometry geom; // Required buffers vector<vec3> positions; vector<vec3> normals; // Define the initial tetrahedron - 4 points vector<vec3> v{vec3(0.0f, 0.0f, 1.0f), vec3(0.0f, 0.942809f, -0.333333f), vec3(-0.816497f, -0.471405f, -0.333333f), vec3(0.816497f, -0.471405f, 0.333333f)}; // Divide the triangles divide_triangle({v[0], v[1], v[2]}, subdivisions, positions); divide_triangle({v[3], v[2], v[1]}, subdivisions, positions); divide_triangle({v[0], v[3], v[1]}, subdivisions, positions); divide_triangle({v[0], v[2], v[3]}, subdivisions, positions); // Copy positions (already normalized) into normals buffer normals.insert(normals.end(), positions.begin(), positions.end()); // Add buffers to geometry geom.add_buffer(positions, BUFFER_INDEXES::POSITION_BUFFER); geom.add_buffer(normals, BUFFER_INDEXES::NORMAL_BUFFER); // Create mesh object m = mesh(geom); // Load in simple cell shader eff.add_shader("34_Simple_Cell_Shading/simple_cell.vert", GL_VERTEX_SHADER); eff.add_shader("34_Simple_Cell_Shading/simple_cell.frag", GL_FRAGMENT_SHADER); // Build effect eff.build(); // Colour scale from red to black vector<vec4> colour_data{vec4(0.12f, 0.0f, 0.0f, 1.0f), vec4(0.25f, 0.0f, 0.0f, 1.0f), vec4(0.5f, 0.0f, 0.0f, 1.0f), vec4(1.0f, 0.0f, 0.0f, 1.0f)}; // Create 1D 4x1 texture from colour_data tex = texture(colour_data, 4, 1, false, false); // Set camera properties cam.set_position(vec3(10.0f, 10.0f, 10.0f)); cam.set_target(vec3(0.0f, 0.0f, 0.0f)); auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height()); cam.set_projection(quarter_pi<float>(), aspect, 2.414f, 1000.0f); return true; }
bool load_content() { // Create quad data - two triangles // Positions geom.set_type(GL_TRIANGLES); // set type only need 4 corners for quad vector<vec3> positions { vec3(1.0, 1.0, 0.0), vec3(0.0, 0.0, -1.0), vec3(2.0, 0, -1.0), }; // Colours vector<vec4> colours { vec4(1.0f, 0.0f, 0.0f, 1.0f), vec4(1.0f, 0.0f, 0.0f, 1.0f), vec4(1.0f, 0.0f, 0.0f, 1.0f), //vec4(1.0f, 0.0f, 0.0f, 1.0f) //vec4(1.0f, 1.0f, 0.0f, 1.0f), //vec4(1.0f, 1.0f, 0.0f, 1.0f) }; // Add to the geometry geom.add_buffer(positions, BUFFER_INDEXES::POSITION_BUFFER); geom.add_buffer(colours, BUFFER_INDEXES::COLOUR_BUFFER); // Load in shaders eff.add_shader( "..\\resources\\shaders\\basic.vert", // filename GL_VERTEX_SHADER); // type eff.add_shader( "..\\resources\\shaders\\basic.frag", // filename GL_FRAGMENT_SHADER); // type // Build effect eff.build(); // Set camera properties cam.set_position(vec3(10.0f, 10.0f, 10.0f)); cam.set_target(vec3(0.0f, 0.0f, 1.0f)); auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height()); cam.set_projection(quarter_pi<float>(), aspect, 2.414f, 1000.0f); return true; }
bool load_content() { // Set to points type geom.set_type(GL_POINTS); // Create sierpinski gasket create_sierpinski(geom); // Load in shaders eff.add_shader("shaders/basic.vert", GL_VERTEX_SHADER); eff.add_shader("shaders/basic.frag", GL_FRAGMENT_SHADER); // Build effect eff.build(); // Set camera properties cam.set_position(vec3(2.0f, 2.0f, 2.0f)); cam.set_target(vec3(0.0f, 0.0f, 0.0f)); auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height()); cam.set_projection(quarter_pi<float>(), aspect, 2.414f, 1000.0f); return true; }
bool load_content() { // ********************************* // Load in model, models/teapot.obj mesh m(geometry("models/teapot.obj")); // Load in texture, textures/checker.png tex = texture("textures/checker.png"); // ********************************* // Load in shaders eff.add_shader("27_Texturing_Shader/simple_texture.vert", GL_VERTEX_SHADER); eff.add_shader("27_Texturing_Shader/simple_texture.frag", GL_FRAGMENT_SHADER); // Build effect eff.build(); // Set camera properties cam.set_position(vec3(200.0f, 200.0f, 200.0f)); cam.set_target(vec3(0.0f, 0.0f, 0.0f)); cam.set_projection(quarter_pi<float>(), renderer::get_screen_aspect(), 0.1f, 1000.0f); return true; }
bool load_content() { // Construct geometry object geometry geom; geom.set_type(GL_QUADS); // Create quad data // Positions vector<vec3> positions { vec3(-1.0f, 1.0f, 0.0f), vec3(-1.0f, -1.0f, 0.0f), vec3(1.0f, -1.0f, 0.0f), vec3(1.0f, 1.0f, 0.0f) }; // Texture coordinates vector<vec2> tex_coords { vec2(0.0f, 1.0f), vec2(0.0f, 0.0f), vec2(1.0f, 0.0f), vec2(1.0f, 1.0f) }; // Add to the geometry geom.add_buffer(positions, BUFFER_INDEXES::POSITION_BUFFER); geom.add_buffer(tex_coords, BUFFER_INDEXES::TEXTURE_COORDS_0); // Create mesh object m = mesh(geom); // Scale geometry m.get_transform().scale = vec3(10.0f, 10.0f, 10.0f); // ******************** // Load in blend shader // ******************** eff.add_shader("..\\resources\\shaders\\blend.vert", GL_VERTEX_SHADER); // vertex eff.add_shader("..\\resources\\shaders\\blend.frag", GL_FRAGMENT_SHADER); // fragment // ************ // Build effect // ************ eff.build(); // ********************** // Load main two textures // ********************** texs[0] = new texture("..\\resources\\textures\\grass.png", false, false); texs[1] = new texture("..\\resources\\textures\\stonygrass.jpg", false, false); // ************** // Load blend map // ************** blend_map = texture("..\\resources\\textures\\blend_map.jpg", false, false); // Set camera properties cam.set_position(vec3(0.0f, 0.0f, 30.0f)); cam.set_target(vec3(0.0f, 0.0f, 0.0f)); auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height()); cam.set_projection(quarter_pi<float>(), aspect, 2.414f, 1000.0f); return true; }
bool load_content() { // Create plane mesh meshes["plane"] = mesh(geometry_builder::create_plane()); // Create scene meshes["box"] = mesh(geometry_builder::create_box()); meshes["tetra"] = mesh(geometry_builder::create_tetrahedron()); meshes["pyramid"] = mesh(geometry_builder::create_pyramid()); meshes["disk"] = mesh(geometry_builder::create_disk(20)); meshes["cylinder"] = mesh(geometry_builder::create_cylinder(20, 20)); meshes["sphere"] = mesh(geometry_builder::create_sphere(20, 20)); meshes["torus"] = mesh(geometry_builder::create_torus(20, 20, 1.0f, 5.0f)); // Transform objects meshes["box"].get_transform().scale = vec3(5.0f, 5.0f, 5.0f); meshes["box"].get_transform().translate(vec3(-10.0f, 2.5f, -30.0f)); meshes["tetra"].get_transform().scale = vec3(4.0f, 4.0f, 4.0f); meshes["tetra"].get_transform().translate(vec3(-30.0f, 10.0f, -10.0f)); meshes["pyramid"].get_transform().scale = vec3(5.0f, 5.0f, 5.0f); meshes["pyramid"].get_transform().translate(vec3(-10.0f, 7.5f, -30.0f)); meshes["disk"].get_transform().scale = vec3(3.0f, 1.0f, 3.0f); meshes["disk"].get_transform().translate(vec3(-10.0f, 11.5f, -30.0f)); meshes["disk"].get_transform().rotate(vec3(half_pi<float>(), 0.0f, 0.0f)); meshes["cylinder"].get_transform().scale = vec3(5.0f, 5.0f, 5.0f); meshes["cylinder"].get_transform().translate(vec3(-25.0f, 2.5f, -25.0f)); meshes["sphere"].get_transform().scale = vec3(2.5f, 2.5f, 2.5f); meshes["sphere"].get_transform().translate(vec3(-25.0f, 10.0f, -25.0f)); meshes["torus"].get_transform().translate(vec3(-25.0f, 10.0f, -25.0f)); meshes["torus"].get_transform().rotate(vec3(half_pi<float>(), 0.0f, 0.0f)); // ********************************* // Set materials // - all emissive is black // - all specular is white // - all shininess is 25 // Red box materials["box"].set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f)); materials["box"].set_diffuse(vec4(1.0f, 0.0f, 0.0f, 1.0f)); materials["box"].set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); materials["box"].set_shininess(25.0f); // Green tetra materials["tetra"].set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f)); materials["tetra"].set_diffuse(vec4(0.0f, 1.0f, 0.0f, 1.0f)); materials["tetra"].set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); materials["tetra"].set_shininess(25.0f); // Blue pyramid materials["pyramid"].set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f)); materials["pyramid"].set_diffuse(vec4(0.0f, 0.0f, 1.0f, 1.0f)); materials["pyramid"].set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); materials["pyramid"].set_shininess(25.0f); // Yellow disk materials["disk"].set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f)); materials["disk"].set_diffuse(vec4(0.0f, 1.0f, 1.0f, 1.0f)); materials["disk"].set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); materials["disk"].set_shininess(25.0f); // Magenta cylinder materials["cylinder"].set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f)); materials["cylinder"].set_diffuse(vec4(1.0f, 0.0f, 1.0f, 1.0f)); materials["cylinder"].set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); materials["cylinder"].set_shininess(25.0f); // Cyan sphere materials["sphere"].set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f)); materials["sphere"].set_diffuse(vec4(0.75f, 1.0f, 1.0f, 1.0f)); materials["sphere"].set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); materials["sphere"].set_shininess(25.0f); // White torus materials["torus"].set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f)); materials["torus"].set_diffuse(vec4(1.0f, 1.0f, 1.0f, 1.0f)); materials["torus"].set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); materials["torus"].set_shininess(25.0f); // ********************************* // Load texture tex = texture("textures/checker2.png"); // Set lighting values // ********************************* // Point 0, Position (-25, 5, -15) // Red, 20 range points[0].set_position(vec3(-25, 5, -15)); points[0].set_light_colour(vec4(1, 0, 0, 1)); points[0].set_range(20); // Point 1, Position (-25, 5, -35) // Red,20 range points[1].set_position(vec3(-25, 5, -35)); points[1].set_light_colour(vec4(1, 0, 0, 1)); points[1].set_range(20); // Point 2,Position (-10, 5, -15) // Red,20 range points[2].set_position(vec3(-10, 5, -15)); points[2].set_light_colour(vec4(1, 0, 0, 1)); points[2].set_range(20); // Point 3,Position (-10, 5, -35) // Red,20 range points[3].set_position(vec3(-10, 5, -35)); points[3].set_light_colour(vec4(1, 0, 0, 1)); points[3].set_range(20); // Spot 0, Position (-25, 10, -15) // Green, Direction (1, -1, -1) normalized // 20 range,0.5 power spots[0].set_position(vec3(-25, 10, -15)); spots[0].set_light_colour(vec4(0, 1, 0, 1)); spots[0].set_range(20); spots[0].set_power(0.5f); spots[0].set_direction(normalize(vec3(1, -1, -1))); // Spot 1,Position (-25, 10, -35) // Green,Direction (1, -1, 1) normalized // 20 range,0.5 power spots[1].set_position(vec3(-25, 10, -15)); spots[1].set_light_colour(vec4(0, 1, 0, 1)); spots[1].set_range(20); spots[1].set_power(0.5f); spots[1].set_direction(normalize(vec3(1, -1, 1))); // Spot 2,Position (-10, 10, -15) // Green,Direction (-1, -1, -1) normalized // 20 range,0.5 power spots[2].set_position(vec3(-25, 10, -15)); spots[2].set_light_colour(vec4(0, 1, 0, 1)); spots[2].set_range(20); spots[2].set_power(0.5f); spots[2].set_direction(normalize(vec3(-1, -1, -1))); // Spot 3,Position (-10, 10, -35) // Green,Direction (-1, -1, 1) normalized // 20 range,0.5 power spots[3].set_position(vec3(-25, 10, -15)); spots[3].set_light_colour(vec4(0, 1, 0, 1)); spots[3].set_range(20); spots[3].set_power(0.5f); spots[3].set_direction(normalize(vec3(-1, -1, -1))); // Spot 4,Position (-17.5, 15, -25) // Blue,Direction (0, -1, 0) // 30 range,1.0 power spots[4].set_position(vec3(-25, 10, -15)); spots[4].set_light_colour(vec4(0, 0, 1, 1)); spots[4].set_range(20); spots[4].set_power(1.0f); spots[4].set_direction(normalize(vec3(0, -1, 0))); // Set lighting values light.set_ambient_intensity(vec4(0.3f, 0.3f, 0.3f, 1.0f)); light.set_direction(vec3(1.0f, 1.0f, -1.0f)); light.set_light_colour(vec4(1.0f, 1.0f, 1.0f, 1.0f)); // Load in shaders eff.add_shader("52_Multifile_Shaders/shader.vert", GL_VERTEX_SHADER); // Name of fragment shaders required vector<string> frag_shaders{ "52_Multifile_Shaders/shader.frag", "shaders/part_direction.frag", "shaders/part_point.frag", "shaders/part_spot.frag" }; eff.add_shader(frag_shaders, GL_FRAGMENT_SHADER); // Build effect eff.build(); // Set camera properties cam.set_position(vec3(50.0f, 10.0f, 50.0f)); cam.set_target(vec3(0.0f, 0.0f, 0.0f)); cam.set_projection(quarter_pi<float>(), renderer::get_screen_aspect(), 0.1f, 1000.0f); return true; }
bool load_content() { // Create cube data - twelve triangles triangles // Positions geom.set_type(GL_QUADS); vector<vec3> positions { // **************************************** // Add the position data for triangles here // **************************************** // Front vec3(-1.0f, 1.0f, 0.0f), // 2 vec3(-1.0f, -1.0f, 0.0f), // 0 vec3(1.0f, -1.0f, 0.0f), // 1 vec3(1.0f, 1.0f, 0.0f), // 3 // Back vec3(-1.0f, 1.0f, -2.0f), // 6 vec3(1.0f, 1.0f, -2.0f), // 7 vec3(1.0f, -1.0f, -2.0f), // 5 vec3(-1.0f, -1.0f, -2.0f), // 4 // Right vec3(1.0f, 1.0f, -2.0f), // 7 vec3(1.0f, 1.0f, 0.0f), // 3 vec3(1.0f, -1.0f, 0.0f), // 1 vec3(1.0f, -1.0f, -2.0f), // 5 // Left vec3(-1.0f, 1.0f, 0.0f), // 2 vec3(-1.0f, 1.0f, -2.0f), // 6 vec3(-1.0f, -1.0f, -2.0f), // 4 vec3(-1.0f, -1.0f, 0.0f), // 0 // Top vec3(-1.0f, -1.0f, 0.0f), // 0 vec3(-1.0f, -1.0f, -2.0f), // 4 vec3(1.0f, -1.0f, -2.0f), // 5 vec3(1.0f, -1.0f, 0.0f), // 1 // Bottom vec3(-1.0f, 1.0f, -2.0f), // 6 vec3(-1.0f, 1.0f, 0.0f), // 2 vec3(1.0f, 1.0f, 0.0f), // 3 vec3(1.0f, 1.0f, -2.0f), // 7 }; // Colours vector<vec4> colours; for (auto i = 0; i < 9; ++i) //positions.size(); ++i) colours.push_back(vec4(1.0f, 0.0f, 0.0f, 1.0f)); for (auto i = 9; i < 16; ++i) colours.push_back(vec4(0.0f, 1.0f, 0.0f, 1.0f)); for (auto i = 16; i < positions.size(); ++i) colours.push_back(vec4(0.0f, 0.0f, 1.0f, 1.0f)); //glDisable(GL_DEPTH_TEST); // Add to the geometry geom.add_buffer(positions, BUFFER_INDEXES::POSITION_BUFFER); geom.add_buffer(colours, BUFFER_INDEXES::COLOUR_BUFFER); // Load in shaders eff.add_shader( "..\\resources\\shaders\\basic.vert", // filename GL_VERTEX_SHADER); // type eff.add_shader( "..\\resources\\shaders\\basic.frag", // filename GL_FRAGMENT_SHADER); // type // Build effect eff.build(); // Set camera properties cam.set_position(vec3(10.0f, 10.0f, 10.0f)); cam.set_target(vec3(0.0f, 0.0f, 0.0f)); auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height()); cam.set_projection(quarter_pi<float>(), aspect, 2.414f, 1000.0f); return true; }
bool load_content() { // Construct geometry object geometry geom; geometry geom2; geom.set_type(GL_QUADS); geom2.set_type(GL_QUADS); // Create triangle data // Positions vector<vec3> positions { vec3(-1.0f, 1.0f, 0.0f), vec3(-1.0f, -1.0f, 0.0f), vec3(1.0f, -1.0f, 0.0f), vec3(1.0f, 1.0f, 0.0f), vec3(1.0f, 1.0f, 0.0f), vec3(1.0f, -1.0f, 0.0f), vec3(1.0f, -1.0f, -2.0f), vec3(1.0f, 1.0f, -2.0f) }; vector<vec3> pos2 { vec3(-1.0f, 1.0f, -2.0f), vec3(-1.0f, 1.0f, 0.0f), vec3(1.0f, 1.0f, 0.0f), vec3(1.0f, 1.0f, -2.0f) }; /* vec3(-1.0f, 1.0f, -2.0f); vec3(-1.0f, -1.0f, 0.0f); vec3(1.0f, 1.0f, 0.0f); vec3(1.0f, 1.0f, -2.0f); */ // *************************************** // Define texture coordinates for triangle // *************************************** vector<vec2> tex_coords { vec2(0.0f, 1.0f), vec2(0.0f, 0.0f), vec2(0.5f, 0.0f), vec2(0.5f, 1.0f), vec2(0.5f, 1.0f), vec2(0.5f, 0.0f), vec2(1.0f, 0.0f), vec2(1.0f, 1.0f) }; vector<vec2> tex_coordsTOP { vec2(0.0f, 1.0f), vec2(0.0f, 0.0f), vec2(1.0f, 0.0f), vec2(1.0f, 1.0f), }; // Add to the geometry geom.add_buffer(positions, BUFFER_INDEXES::POSITION_BUFFER); geom2.add_buffer(pos2, BUFFER_INDEXES::POSITION_BUFFER); // ***************************************** // Add texture coordinate buffer to geometry // ***************************************** geom.add_buffer(tex_coords, BUFFER_INDEXES::TEXTURE_COORDS_0); geom2.add_buffer(tex_coordsTOP, BUFFER_INDEXES::TEXTURE_COORDS_0); // Create mesh object m = mesh(geom); m2 = mesh(geom2); // **************************** // Load in texture shaders here // **************************** eff.add_shader("..\\resources\\shaders\\simple_texture.vert", GL_VERTEX_SHADER); eff.add_shader("..\\resources\\shaders\\simple_texture.frag", GL_FRAGMENT_SHADER); // ************ // Build effect // ************ eff.build(); // ********************* // Load texture sign.jpg // ********************* tex = texture("..\\resources\\textures\\sign.jpg"); tex2 = texture("..\\resources\\textures\\wood.dds"); // Set camera properties cam.set_position(vec3(10.0f, 10.0f, 10.0f)); cam.set_target(vec3(0.0f, 0.0f, 0.0f)); auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height()); cam.set_projection(quarter_pi<float>(), aspect, 2.414f, 1000.0f); return true; }
bool load_content() { // ********************************* // Create frame buffer - use screen width and height // Create screen quad // ********************************* // Create plane mesh meshes["plane"] = mesh(geometry_builder::create_plane()); // Create scene meshes["box"] = mesh(geometry_builder::create_box()); meshes["tetra"] = mesh(geometry_builder::create_tetrahedron()); meshes["pyramid"] = mesh(geometry_builder::create_pyramid()); meshes["disk"] = mesh(geometry_builder::create_disk(20)); meshes["cylinder"] = mesh(geometry_builder::create_cylinder(20, 20)); meshes["sphere"] = mesh(geometry_builder::create_sphere(20, 20)); meshes["torus"] = mesh(geometry_builder::create_torus(20, 20, 1.0f, 5.0f)); // Transform objects meshes["box"].get_transform().scale = vec3(5.0f, 5.0f, 5.0f); meshes["box"].get_transform().translate(vec3(-10.0f, 2.5f, -30.0f)); meshes["tetra"].get_transform().scale = vec3(4.0f, 4.0f, 4.0f); meshes["tetra"].get_transform().translate(vec3(-30.0f, 10.0f, -10.0f)); meshes["pyramid"].get_transform().scale = vec3(5.0f, 5.0f, 5.0f); meshes["pyramid"].get_transform().translate(vec3(-10.0f, 7.5f, -30.0f)); meshes["disk"].get_transform().scale = vec3(3.0f, 1.0f, 3.0f); meshes["disk"].get_transform().translate(vec3(-10.0f, 11.5f, -30.0f)); meshes["disk"].get_transform().rotate(vec3(half_pi<float>(), 0.0f, 0.0f)); meshes["cylinder"].get_transform().scale = vec3(5.0f, 5.0f, 5.0f); meshes["cylinder"].get_transform().translate(vec3(-25.0f, 2.5f, -25.0f)); meshes["sphere"].get_transform().scale = vec3(2.5f, 2.5f, 2.5f); meshes["sphere"].get_transform().translate(vec3(-25.0f, 10.0f, -25.0f)); meshes["torus"].get_transform().translate(vec3(-25.0f, 10.0f, -25.0f)); meshes["torus"].get_transform().rotate(vec3(half_pi<float>(), 0.0f, 0.0f)); // Set materials // Red box meshes["box"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f)); meshes["box"].get_material().set_diffuse(vec4(1.0f, 0.0f, 0.0f, 1.0f)); meshes["box"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); meshes["box"].get_material().set_shininess(25.0f); // Green tetra meshes["tetra"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f)); meshes["tetra"].get_material().set_diffuse(vec4(0.0f, 1.0f, 0.0f, 1.0f)); meshes["tetra"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); meshes["tetra"].get_material().set_shininess(25.0f); // Blue pyramid meshes["pyramid"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f)); meshes["pyramid"].get_material().set_diffuse(vec4(0.0f, 0.0f, 1.0f, 1.0f)); meshes["pyramid"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); meshes["pyramid"].get_material().set_shininess(25.0f); // Yellow disk meshes["disk"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f)); meshes["disk"].get_material().set_diffuse(vec4(1.0f, 1.0f, 0.0f, 1.0f)); meshes["disk"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); meshes["disk"].get_material().set_shininess(25.0f); // Magenta cylinder meshes["cylinder"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f)); meshes["cylinder"].get_material().set_diffuse(vec4(1.0f, 0.0f, 1.0f, 1.0f)); meshes["cylinder"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); meshes["cylinder"].get_material().set_shininess(25.0f); // Cyan sphere meshes["sphere"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f)); meshes["sphere"].get_material().set_diffuse(vec4(0.0f, 1.0f, 1.0f, 1.0f)); meshes["sphere"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); meshes["sphere"].get_material().set_shininess(25.0f); // White torus meshes["torus"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f)); meshes["torus"].get_material().set_diffuse(vec4(1.0f, 1.0f, 1.0f, 1.0f)); meshes["torus"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); meshes["torus"].get_material().set_shininess(25.0f); // Load texture tex = texture("textures/checked.gif"); // Set lighting values light.set_ambient_intensity(vec4(0.3f, 0.3f, 0.3f, 1.0f)); light.set_light_colour(vec4(1.0f, 1.0f, 1.0f, 1.0f)); light.set_direction(vec3(1.0f, 1.0f, -1.0f)); // Load in shaders eff.add_shader("48_Phong_Shading/phong.vert", GL_VERTEX_SHADER); eff.add_shader("48_Phong_Shading/phong.frag", GL_FRAGMENT_SHADER); tex_eff.add_shader("27_Texturing_Shader/simple_texture.vert", GL_VERTEX_SHADER); tex_eff.add_shader("72_Blur/blur.frag", GL_FRAGMENT_SHADER); // Build effects eff.build(); tex_eff.build(); // Set camera properties cam.set_position(vec3(50.0f, 10.0f, 50.0f)); cam.set_target(vec3(0.0f, 0.0f, 0.0f)); auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height()); cam.set_projection(quarter_pi<float>(), aspect, 2.414f, 1000.0f); return true; }
bool load_content() { // ********************************* // Create shadow map- use screen size // Create plane mesh // Create "teapot" mesh by loading in models/teapot.obj // Need to rotate the teapot on x by negative pi/2 // Scale the teapot - (0.1, 0.1, 0.1) // ********************************* // Load texture tex = texture("textures/checker.png"); // *********************** // Set materials // - all emissive is black // - all specular is white // - all shininess is 25 // *********************** // White plane meshes["plane"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f)); meshes["plane"].get_material().set_diffuse(vec4(1.0f, 1.0f, 1.0f, 1.0f)); meshes["plane"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); meshes["plane"].get_material().set_shininess(25.0f); // Red teapot meshes["teapot"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f)); meshes["teapot"].get_material().set_diffuse(vec4(1.0f, 1.0f, 1.0f, 1.0f)); meshes["teapot"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); meshes["teapot"].get_material().set_shininess(25.0f); // ******************* // Set spot properties // ******************* // Pos (20, 30, 0), White // Direction (-1, -1, 0) normalized // 50 range, 10 power spot.set_position(vec3(30.0f, 20.0f, 0.0f)); spot.set_light_colour(vec4(1.0f, 1.0f, 1.0f, 1.0f)); spot.set_direction(normalize(vec3(-1.0f, -1.0f, 0.0f))); spot.set_range(500.0f); spot.set_power(10.0f); // Load in shaders main_eff.add_shader("54_Shadowing/shadow.vert", GL_VERTEX_SHADER); vector<string> frag_shaders{"54_Shadowing/shadow.frag", "shaders/part_spot.frag", "shaders/part_shadow.frag"}; main_eff.add_shader(frag_shaders, GL_FRAGMENT_SHADER); shadow_eff.add_shader("50_Spot_Light/spot.vert", GL_VERTEX_SHADER); shadow_eff.add_shader("50_Spot_Light/spot.frag", GL_FRAGMENT_SHADER); // Build effects main_eff.build(); shadow_eff.build(); // Set camera properties cam.set_position(vec3(0.0f, 50.0f, -75.0f)); cam.set_target(vec3(0.0f, 0.0f, 0.0f)); cam.set_projection(quarter_pi<float>(), renderer::get_screen_aspect(), 0.1f, 1000.0f); return true; }
bool load_content() { // Create plane mesh meshes["plane"] = mesh(geometry_builder::create_plane()); // Create scene meshes["box"] = mesh(geometry_builder::create_box()); meshes["tetra"] = mesh(geometry_builder::create_tetrahedron()); meshes["pyramid"] = mesh(geometry_builder::create_pyramid()); meshes["disk"] = mesh(geometry_builder::create_disk(20)); meshes["cylinder"] = mesh(geometry_builder::create_cylinder(20, 20)); meshes["sphere"] = mesh(geometry_builder::create_sphere(20, 20)); meshes["torus"] = mesh(geometry_builder::create_torus(20, 20, 1.0f, 5.0f)); // Transform objects meshes["box"].get_transform().scale = vec3(5.0f, 5.0f, 5.0f); meshes["box"].get_transform().translate(vec3(-10.0f, 2.5f, -30.0f)); meshes["tetra"].get_transform().scale = vec3(4.0f, 4.0f, 4.0f); meshes["tetra"].get_transform().translate(vec3(-30.0f, 10.0f, -10.0f)); meshes["pyramid"].get_transform().scale = vec3(5.0f, 5.0f, 5.0f); meshes["pyramid"].get_transform().translate(vec3(-10.0f, 7.5f, -30.0f)); meshes["disk"].get_transform().scale = vec3(3.0f, 1.0f, 3.0f); meshes["disk"].get_transform().translate(vec3(-10.0f, 11.5f, -30.0f)); meshes["disk"].get_transform().rotate(vec3(half_pi<float>(), 0.0f, 0.0f)); meshes["cylinder"].get_transform().scale = vec3(5.0f, 5.0f, 5.0f); meshes["cylinder"].get_transform().translate(vec3(-25.0f, 2.5f, -25.0f)); meshes["sphere"].get_transform().scale = vec3(2.5f, 2.5f, 2.5f); meshes["sphere"].get_transform().translate(vec3(-25.0f, 10.0f, -25.0f)); meshes["torus"].get_transform().translate(vec3(-25.0f, 10.0f, -25.0f)); meshes["torus"].get_transform().rotate(vec3(half_pi<float>(), 0.0f, 0.0f)); // ********************************* // Set materials // - all emissive is black // - all specular is white // - all shininess is 25 // Red box meshes["box"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f)); meshes["box"].get_material().set_diffuse(vec4(1.0f, 0.0f, 0.0f, 1.0f)); meshes["box"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); meshes["box"].get_material().set_shininess(25.0f); // Green tetra meshes["tetra"].get_material().set_emissive(vec4(1.0f, 1.0f, 0.0f, 1.0f)); meshes["tetra"].get_material().set_diffuse(vec4(0.0f, 1.0f, 0.0f, 1.0f)); meshes["tetra"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); meshes["tetra"].get_material().set_shininess(25.0f); // Blue pyramid meshes["pyramid"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f)); meshes["pyramid"].get_material().set_diffuse(vec4(0.0f, 0.0f, 1.0f, 1.0f)); meshes["pyramid"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); meshes["pyramid"].get_material().set_shininess(25.0f); // Yellow disk meshes["disk"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f)); meshes["disk"].get_material().set_diffuse(vec4(1.0f, 1.0f, 0.0f, 1.0f)); meshes["disk"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); meshes["disk"].get_material().set_shininess(25.0f); // Magenta cylinder meshes["cylinder"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f)); meshes["cylinder"].get_material().set_diffuse(vec4(1.0f, 0.0f, 1.0f, 1.0f)); meshes["cylinder"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); meshes["cylinder"].get_material().set_shininess(25.0f); // Cyan sphere meshes["sphere"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f)); meshes["sphere"].get_material().set_diffuse(vec4(0.0f, 1.0f, 1.0f, 1.0f)); meshes["sphere"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); meshes["sphere"].get_material().set_shininess(25.0f); // White torus meshes["torus"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f)); meshes["torus"].get_material().set_diffuse(vec4(1.0f, 1.0f, 1.0f, 1.0f)); meshes["torus"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f)); meshes["torus"].get_material().set_shininess(25.0f); // ********************************* // Load texture tex = texture("textures/checker.png"); // ********************************* // Set lighting values, Position (-25, 10, -10) light.set_position(vec3(-25, 10, -10)); // Light colour white light.set_light_colour(vec4(1.0f, 1.0f, 1.0f, 1.0f)); // Set range to 20 light.set_range(20); // Load in shaders eff.add_shader("49_Point_Light/point.vert", GL_VERTEX_SHADER); eff.add_shader("49_Point_Light/point.frag", GL_FRAGMENT_SHADER); // Build effect eff.build(); // ********************************* // Set camera properties cam.set_position(vec3(50.0f, 10.0f, 50.0f)); cam.set_target(vec3(0.0f, 0.0f, 0.0f)); cam.set_projection(quarter_pi<float>(), renderer::get_screen_aspect(), 0.1f, 1000.0f); return true; }