diff --git a/OpenGL/playground/.vscode/settings.json b/OpenGL/playground/.vscode/settings.json index 6c8158c..5ee1dc3 100644 --- a/OpenGL/playground/.vscode/settings.json +++ b/OpenGL/playground/.vscode/settings.json @@ -35,6 +35,23 @@ "type_traits": "cpp", "tuple": "cpp", "typeinfo": "cpp", - "utility": "cpp" + "utility": "cpp", + "csignal": "cpp", + "cstdarg": "cpp", + "atomic": "cpp", + "strstream": "cpp", + "bitset": "cpp", + "complex": "cpp", + "condition_variable": "cpp", + "deque": "cpp", + "list": "cpp", + "functional": "cpp", + "iomanip": "cpp", + "memory": "cpp", + "mutex": "cpp", + "thread": "cpp", + "cinttypes": "cpp", + "typeindex": "cpp", + "variant": "cpp" } } \ No newline at end of file diff --git a/OpenGL/playground/output b/OpenGL/playground/output index c09bd68..831eef8 100755 Binary files a/OpenGL/playground/output and b/OpenGL/playground/output differ diff --git a/OpenGL/playground/resources/shaders/phong.frag b/OpenGL/playground/resources/shaders/phong.frag index d861017..c7e0609 100644 --- a/OpenGL/playground/resources/shaders/phong.frag +++ b/OpenGL/playground/resources/shaders/phong.frag @@ -9,7 +9,7 @@ vec3 viewPos = vec3(0.0, 0.0, 0.0); out vec4 outColour; vec3 objectColour = vec3(0.58, 0.61, 0.627); -vec3 lightColour = vec3(0.0, 1.0, 1.0); +vec3 lightColour = vec3(1.0, 0.0, 1.0); void main() { float ambientStrength = 0.5; diff --git a/OpenGL/playground/src/main.cpp b/OpenGL/playground/src/main.cpp index 35c9a80..1061f9c 100644 --- a/OpenGL/playground/src/main.cpp +++ b/OpenGL/playground/src/main.cpp @@ -56,7 +56,7 @@ int main(int argc, char** argv) { window = SDL_CreateWindow("OpenGL Playground V1.0", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - 640, 480, + 1280, 720, SDL_WINDOW_OPENGL); glContext = SDL_GL_CreateContext(window); SDL_GL_SetSwapInterval(0); @@ -128,7 +128,7 @@ int main(int argc, char** argv) { glUniformMatrix4fv(uniView, 1, GL_FALSE, glm::value_ptr(view)); // Projection matrice - glm::mat4 proj = glm::perspective(glm::radians(45.0f), 640.0f / 480.0f, 1.0f, 1000.0f); + glm::mat4 proj = glm::perspective(glm::radians(45.0f), 1280.0f / 720.0f, 1.0f, 1000.0f); // Get uniform and send it to the GPU GLint uniProj = glGetUniformLocation(simpleShader.getProgram(), "proj"); glUniformMatrix4fv(uniProj, 1, GL_FALSE, glm::value_ptr(proj)); diff --git a/OpenGL/playground/src/object.cpp b/OpenGL/playground/src/object.cpp index ef1caa5..c2fdef0 100644 --- a/OpenGL/playground/src/object.cpp +++ b/OpenGL/playground/src/object.cpp @@ -39,3 +39,20 @@ void LoadOBJ(Logger& logger, std::string file, std::vector& vertices, logger << LOGGER_INFO << "Loaded OBJ: " << file << LOGGER_ENDL; } + +void FlatShade(std::vector& vertices, std::vector& normals, std::vector& elements) { + std::vector shared_vertices; + for (int i = 0; i < elements.size(); i++) { + vertices.push_back(shared_vertices[elements[i]]); + if ((i % 3) == 2) { + GLushort ia = elements[i-2]; + GLushort ib = elements[i-1]; + GLushort ic = elements[i]; + glm::vec3 normal = glm::normalize(glm::cross( + shared_vertices[ic] - shared_vertices[ia], + shared_vertices[ib] - shared_vertices[ia])); + for (int n = 0; n < 3; n++) + normals.push_back(normal); + } + } +} diff --git a/OpenGL/playground/src/object.h b/OpenGL/playground/src/object.h index cac6fc6..52e089f 100644 --- a/OpenGL/playground/src/object.h +++ b/OpenGL/playground/src/object.h @@ -26,4 +26,8 @@ void LoadOBJ(Logger& logger, std::vector& normals, std::vector& elements); +void FlatShade(std::vector& vertices, + std::vector& normals, + std::vector& elements); + #endif