diff --git a/CMakeLists.txt b/CMakeLists.txt index b5db556..238b01e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,9 +40,9 @@ if (UNIX) endif (UNIX) include_directories(${executable} - #${PNG_INCLUDE_DIR} - #${JPEG_INCLUDE_DIR} - ${IncludeDIR} + #${PNG_INCLUDE_DIR} + #${JPEG_INCLUDE_DIR} + ${IncludeDIR} ) file(GLOB SourceFiles @@ -53,8 +53,8 @@ file(GLOB SourceFiles add_executable(${executable} ${SourceFiles}) set_target_properties(${executable} PROPERTIES - CXX_STANDARD 17 - CXX_EXTENSIONS OFF + CXX_STANDARD 17 + CXX_EXTENSIONS OFF ) if (UNIX) @@ -63,7 +63,7 @@ if (UNIX) #SDL2_image #PNG::PNG #JPEG::JPEG - OpenGL::OpenGL + OpenGL::OpenGL OpenGL::GL Threads::Threads ) @@ -80,5 +80,5 @@ if (WIN32) endif (WIN32) target_link_libraries(${executable} - ${CMAKE_DL_LIBS} + ${CMAKE_DL_LIBS} ) diff --git a/OBJLoaderExample.cpp b/include/OBJLoaderExample.cpp similarity index 97% rename from OBJLoaderExample.cpp rename to include/OBJLoaderExample.cpp index 75539ef..4510f1f 100644 --- a/OBJLoaderExample.cpp +++ b/include/OBJLoaderExample.cpp @@ -1,80 +1,80 @@ -#define TINYOBJLOADER_IMPLEMENTATION // define this in only *one* .cc -#include "tiny_obj_loader.h" - -std::string inputfile = "cornell_box.obj"; -tinyobj::attrib_t attrib; -std::vector shapes; -std::vector materials; - -std::string warn; -std::string err; -bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &warn, &err, inputfile.c_str()); - -if (!err.empty()) { // `err` may contain warning message. - std::cerr << err << std::endl; -} - -if (!ret) { - exit(1); -} - -// Loop over shapes -for (size_t s = 0; s < shapes.size(); s++) { - // Loop over faces(polygon) - size_t index_offset = 0; - for (size_t f = 0; f < shapes[s].mesh.num_face_vertices.size(); f++) { - int fv = shapes[s].mesh.num_face_vertices[f]; - - // Loop over vertices in the face. - for (size_t v = 0; v < fv; v++) { - // access to vertex - tinyobj::index_t idx = shapes[s].mesh.indices[index_offset + v]; - tinyobj::real_t vx = attrib.vertices[3*idx.vertex_index+0]; - tinyobj::real_t vy = attrib.vertices[3*idx.vertex_index+1]; - tinyobj::real_t vz = attrib.vertices[3*idx.vertex_index+2]; - tinyobj::real_t nx = attrib.normals[3*idx.normal_index+0]; - tinyobj::real_t ny = attrib.normals[3*idx.normal_index+1]; - tinyobj::real_t nz = attrib.normals[3*idx.normal_index+2]; - tinyobj::real_t tx = attrib.texcoords[2*idx.texcoord_index+0]; - tinyobj::real_t ty = attrib.texcoords[2*idx.texcoord_index+1]; - // Optional: vertex colors - // tinyobj::real_t red = attrib.colors[3*idx.vertex_index+0]; - // tinyobj::real_t green = attrib.colors[3*idx.vertex_index+1]; - // tinyobj::real_t blue = attrib.colors[3*idx.vertex_index+2]; - } - index_offset += fv; - - // per-face material - shapes[s].mesh.material_ids[f]; - } -} - -/** - * attrib_t::vertices => 3 floats per vertex - - v[0] v[1] v[2] v[3] v[n-1] - +-----------+-----------+-----------+-----------+ +-----------+ - | x | y | z | x | y | z | x | y | z | x | y | z | .... | x | y | z | - +-----------+-----------+-----------+-----------+ +-----------+ - -attrib_t::normals => 3 floats per vertex - - n[0] n[1] n[2] n[3] n[n-1] - +-----------+-----------+-----------+-----------+ +-----------+ - | x | y | z | x | y | z | x | y | z | x | y | z | .... | x | y | z | - +-----------+-----------+-----------+-----------+ +-----------+ - -attrib_t::texcoords => 2 floats per vertex - - t[0] t[1] t[2] t[3] t[n-1] - +-----------+-----------+-----------+-----------+ +-----------+ - | u | v | u | v | u | v | u | v | .... | u | v | - +-----------+-----------+-----------+-----------+ +-----------+ - -attrib_t::colors => 3 floats per vertex(vertex color. optional) - - c[0] c[1] c[2] c[3] c[n-1] - +-----------+-----------+-----------+-----------+ +-----------+ - | x | y | z | x | y | z | x | y | z | x | y | z | .... | x | y | z | - +-----------+-----------+-----------+-----------+ +-----------+ -/* +#define TINYOBJLOADER_IMPLEMENTATION // define this in only *one* .cc +#include "tiny_obj_loader.h" + +std::string inputfile = "cornell_box.obj"; +tinyobj::attrib_t attrib; +std::vector shapes; +std::vector materials; + +std::string warn; +std::string err; +bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &warn, &err, inputfile.c_str()); + +if (!err.empty()) { // `err` may contain warning message. + std::cerr << err << std::endl; +} + +if (!ret) { + exit(1); +} + +// Loop over shapes +for (size_t s = 0; s < shapes.size(); s++) { + // Loop over faces(polygon) + size_t index_offset = 0; + for (size_t f = 0; f < shapes[s].mesh.num_face_vertices.size(); f++) { + int fv = shapes[s].mesh.num_face_vertices[f]; + + // Loop over vertices in the face. + for (size_t v = 0; v < fv; v++) { + // access to vertex + tinyobj::index_t idx = shapes[s].mesh.indices[index_offset + v]; + tinyobj::real_t vx = attrib.vertices[3*idx.vertex_index+0]; + tinyobj::real_t vy = attrib.vertices[3*idx.vertex_index+1]; + tinyobj::real_t vz = attrib.vertices[3*idx.vertex_index+2]; + tinyobj::real_t nx = attrib.normals[3*idx.normal_index+0]; + tinyobj::real_t ny = attrib.normals[3*idx.normal_index+1]; + tinyobj::real_t nz = attrib.normals[3*idx.normal_index+2]; + tinyobj::real_t tx = attrib.texcoords[2*idx.texcoord_index+0]; + tinyobj::real_t ty = attrib.texcoords[2*idx.texcoord_index+1]; + // Optional: vertex colors + // tinyobj::real_t red = attrib.colors[3*idx.vertex_index+0]; + // tinyobj::real_t green = attrib.colors[3*idx.vertex_index+1]; + // tinyobj::real_t blue = attrib.colors[3*idx.vertex_index+2]; + } + index_offset += fv; + + // per-face material + shapes[s].mesh.material_ids[f]; + } +} + +/** + * attrib_t::vertices => 3 floats per vertex + + v[0] v[1] v[2] v[3] v[n-1] + +-----------+-----------+-----------+-----------+ +-----------+ + | x | y | z | x | y | z | x | y | z | x | y | z | .... | x | y | z | + +-----------+-----------+-----------+-----------+ +-----------+ + +attrib_t::normals => 3 floats per vertex + + n[0] n[1] n[2] n[3] n[n-1] + +-----------+-----------+-----------+-----------+ +-----------+ + | x | y | z | x | y | z | x | y | z | x | y | z | .... | x | y | z | + +-----------+-----------+-----------+-----------+ +-----------+ + +attrib_t::texcoords => 2 floats per vertex + + t[0] t[1] t[2] t[3] t[n-1] + +-----------+-----------+-----------+-----------+ +-----------+ + | u | v | u | v | u | v | u | v | .... | u | v | + +-----------+-----------+-----------+-----------+ +-----------+ + +attrib_t::colors => 3 floats per vertex(vertex color. optional) + + c[0] c[1] c[2] c[3] c[n-1] + +-----------+-----------+-----------+-----------+ +-----------+ + | x | y | z | x | y | z | x | y | z | x | y | z | .... | x | y | z | + +-----------+-----------+-----------+-----------+ +-----------+ +/* diff --git a/resources/shaders/shadowmap.frag b/resources/shaders/shadowmap.frag deleted file mode 100644 index a963b55..0000000 --- a/resources/shaders/shadowmap.frag +++ /dev/null @@ -1,7 +0,0 @@ -#version 330 - -out float fragdepth; - -void main(){ - gl_FragDepth = gl_FragCoord.z; -} diff --git a/resources/shaders/shadowmap.vert b/resources/shaders/shadowmap.vert deleted file mode 100644 index 39a2f35..0000000 --- a/resources/shaders/shadowmap.vert +++ /dev/null @@ -1,10 +0,0 @@ -#version 330 - -in vec3 vertPos; - -uniform mat4 lightSpaceMatrix; -uniform mat4 model; - -void main() { - gl_Position = lightSpaceMatrix * model * vec4(vertPos, 1.0); -}