From 49d8d895ae631871921d1df829efc14c3cb77832 Mon Sep 17 00:00:00 2001 From: Joey de Vries Date: Wed, 31 May 2017 23:12:15 +0200 Subject: [PATCH] Updated source code to reflect content changes (code re-work): advanced OpenGL and model-loading. --- .../1.1.depth_testing/1.1.depth_testing.vs | 2 +- .../1.1.depth_testing/depth_testing.cpp | 8 +++----- .../1.2.depth_testing_view/1.2.depth_testing.vs | 2 +- .../depth_testing_view.cpp | 6 ++---- .../10.1.instancing_quads/instancing_quads.cpp | 2 +- .../10.2.asteroids/asteroids.cpp | 4 +--- .../asteroids_instanced.cpp | 4 +--- .../anti_aliasing_offscreen.cpp | 10 ++++------ .../2.stencil_testing/stencil_testing.cpp | 4 +--- .../3.1.blending_discard/3.1.blending.vs | 2 +- .../3.1.blending_discard/blending_discard.cpp | 4 +--- .../3.2.blending_sort/3.2.blending.vs | 17 +++++++++-------- .../3.2.blending_sort/blending_sorted.cpp | 6 ++---- .../5.1.framebuffers/framebuffers.cpp | 4 +--- .../5.2.framebuffers.fs | 11 +++++++++++ .../5.2.framebuffers.vs | 15 +++++++++++++++ .../5.2.framebuffers_screen.fs | 12 ++++++++++++ .../5.2.framebuffers_screen.vs | 11 +++++++++++ .../framebuffers_exercise1.cpp | 8 +++----- .../6.1.cubemaps_skybox/6.1.cubemaps.vs | 2 +- .../6.1.cubemaps_skybox/cubemaps_skybox.cpp | 8 +++----- .../6.2.skybox.fs | 11 +++++++++++ .../6.2.skybox.vs | 14 ++++++++++++++ .../cubemaps_environment_mapping.cpp | 6 ++---- .../8.advanced_glsl_ubo/advanced_glsl_ubo.cpp | 4 +--- .../geometry_shader_houses.cpp | 2 +- .../geometry_shader_exploding.cpp | 4 +--- .../normal_visualization.cpp | 4 +--- 28 files changed, 116 insertions(+), 71 deletions(-) create mode 100644 src/4.advanced_opengl/5.2.framebuffers_exercise1/5.2.framebuffers.fs create mode 100644 src/4.advanced_opengl/5.2.framebuffers_exercise1/5.2.framebuffers.vs create mode 100644 src/4.advanced_opengl/5.2.framebuffers_exercise1/5.2.framebuffers_screen.fs create mode 100644 src/4.advanced_opengl/5.2.framebuffers_exercise1/5.2.framebuffers_screen.vs create mode 100644 src/4.advanced_opengl/6.2.cubemaps_environment_mapping/6.2.skybox.fs create mode 100644 src/4.advanced_opengl/6.2.cubemaps_environment_mapping/6.2.skybox.vs diff --git a/src/4.advanced_opengl/1.1.depth_testing/1.1.depth_testing.vs b/src/4.advanced_opengl/1.1.depth_testing/1.1.depth_testing.vs index 95cb343..ddede39 100644 --- a/src/4.advanced_opengl/1.1.depth_testing/1.1.depth_testing.vs +++ b/src/4.advanced_opengl/1.1.depth_testing/1.1.depth_testing.vs @@ -11,5 +11,5 @@ uniform mat4 projection; void main() { TexCoords = aTexCoords; - gl_Position = projection * view * model * vec4(aPos, 1.0f); + gl_Position = projection * view * model * vec4(aPos, 1.0); } \ No newline at end of file diff --git a/src/4.advanced_opengl/1.1.depth_testing/depth_testing.cpp b/src/4.advanced_opengl/1.1.depth_testing/depth_testing.cpp index 08cd6df..0c16c63 100644 --- a/src/4.advanced_opengl/1.1.depth_testing/depth_testing.cpp +++ b/src/4.advanced_opengl/1.1.depth_testing/depth_testing.cpp @@ -30,7 +30,7 @@ float lastY = (float)SCR_HEIGHT / 2.0; bool firstMouse = true; // timing -float deltaTime = 0.0f; +float deltaTime = 0.0f; float lastFrame = 0.0f; int main() @@ -45,13 +45,13 @@ int main() // glfw window creation // -------------------- GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL); - glfwMakeContextCurrent(window); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } + glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwSetCursorPosCallback(window, mouse_callback); glfwSetScrollCallback(window, scroll_callback); @@ -234,7 +234,6 @@ void processInput(GLFWwindow *window) if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); - float cameraSpeed = 2.5 * deltaTime; if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) camera.ProcessKeyboard(FORWARD, deltaTime); if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) @@ -254,7 +253,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height) glViewport(0, 0, width, height); } - // glfw: whenever the mouse moves, this callback is called // ------------------------------------------------------- void mouse_callback(GLFWwindow* window, double xpos, double ypos) @@ -284,7 +282,7 @@ void scroll_callback(GLFWwindow* window, double xoffset, double yoffset) // utility function for loading a 2D texture from file // --------------------------------------------------- -unsigned int loadTexture(char const * path) +unsigned int loadTexture(char const *path) { unsigned int textureID; glGenTextures(1, &textureID); diff --git a/src/4.advanced_opengl/1.2.depth_testing_view/1.2.depth_testing.vs b/src/4.advanced_opengl/1.2.depth_testing_view/1.2.depth_testing.vs index 4a80ebb..cc518f1 100644 --- a/src/4.advanced_opengl/1.2.depth_testing_view/1.2.depth_testing.vs +++ b/src/4.advanced_opengl/1.2.depth_testing_view/1.2.depth_testing.vs @@ -7,5 +7,5 @@ uniform mat4 projection; void main() { - gl_Position = projection * view * model * vec4(aPos, 1.0f); + gl_Position = projection * view * model * vec4(aPos, 1.0); } \ No newline at end of file diff --git a/src/4.advanced_opengl/1.2.depth_testing_view/depth_testing_view.cpp b/src/4.advanced_opengl/1.2.depth_testing_view/depth_testing_view.cpp index aaf9074..182934f 100644 --- a/src/4.advanced_opengl/1.2.depth_testing_view/depth_testing_view.cpp +++ b/src/4.advanced_opengl/1.2.depth_testing_view/depth_testing_view.cpp @@ -45,13 +45,13 @@ int main() // glfw window creation // -------------------- GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL); - glfwMakeContextCurrent(window); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } + glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwSetCursorPosCallback(window, mouse_callback); glfwSetScrollCallback(window, scroll_callback); @@ -234,7 +234,6 @@ void processInput(GLFWwindow *window) if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); - float cameraSpeed = 2.5 * deltaTime; if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) camera.ProcessKeyboard(FORWARD, deltaTime); if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) @@ -254,7 +253,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height) glViewport(0, 0, width, height); } - // glfw: whenever the mouse moves, this callback is called // ------------------------------------------------------- void mouse_callback(GLFWwindow* window, double xpos, double ypos) @@ -284,7 +282,7 @@ void scroll_callback(GLFWwindow* window, double xoffset, double yoffset) // utility function for loading a 2D texture from file // --------------------------------------------------- -unsigned int loadTexture(char const * path) +unsigned int loadTexture(char const *path) { unsigned int textureID; glGenTextures(1, &textureID); diff --git a/src/4.advanced_opengl/10.1.instancing_quads/instancing_quads.cpp b/src/4.advanced_opengl/10.1.instancing_quads/instancing_quads.cpp index 2c36807..5417218 100644 --- a/src/4.advanced_opengl/10.1.instancing_quads/instancing_quads.cpp +++ b/src/4.advanced_opengl/10.1.instancing_quads/instancing_quads.cpp @@ -24,13 +24,13 @@ int main() // glfw window creation // -------------------- GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL); - glfwMakeContextCurrent(window); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } + glfwMakeContextCurrent(window); // glad: load all OpenGL function pointers // --------------------------------------- diff --git a/src/4.advanced_opengl/10.2.asteroids/asteroids.cpp b/src/4.advanced_opengl/10.2.asteroids/asteroids.cpp index 2b65149..a600a98 100644 --- a/src/4.advanced_opengl/10.2.asteroids/asteroids.cpp +++ b/src/4.advanced_opengl/10.2.asteroids/asteroids.cpp @@ -44,13 +44,13 @@ int main() // glfw window creation // -------------------- GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL); - glfwMakeContextCurrent(window); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } + glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwSetCursorPosCallback(window, mouse_callback); glfwSetScrollCallback(window, scroll_callback); @@ -169,7 +169,6 @@ void processInput(GLFWwindow *window) if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); - float cameraSpeed = 2.5 * deltaTime; if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) camera.ProcessKeyboard(FORWARD, deltaTime); if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) @@ -189,7 +188,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height) glViewport(0, 0, width, height); } - // glfw: whenever the mouse moves, this callback is called // ------------------------------------------------------- void mouse_callback(GLFWwindow* window, double xpos, double ypos) diff --git a/src/4.advanced_opengl/10.3.asteroids_instanced/asteroids_instanced.cpp b/src/4.advanced_opengl/10.3.asteroids_instanced/asteroids_instanced.cpp index aaa6766..1fc105f 100644 --- a/src/4.advanced_opengl/10.3.asteroids_instanced/asteroids_instanced.cpp +++ b/src/4.advanced_opengl/10.3.asteroids_instanced/asteroids_instanced.cpp @@ -44,13 +44,13 @@ int main() // glfw window creation // -------------------- GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL); - glfwMakeContextCurrent(window); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } + glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwSetCursorPosCallback(window, mouse_callback); glfwSetScrollCallback(window, scroll_callback); @@ -211,7 +211,6 @@ void processInput(GLFWwindow *window) if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); - float cameraSpeed = 2.5 * deltaTime; if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) camera.ProcessKeyboard(FORWARD, deltaTime); if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) @@ -231,7 +230,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height) glViewport(0, 0, width, height); } - // glfw: whenever the mouse moves, this callback is called // ------------------------------------------------------- void mouse_callback(GLFWwindow* window, double xpos, double ypos) diff --git a/src/4.advanced_opengl/11.anti_aliasing_offscreen/anti_aliasing_offscreen.cpp b/src/4.advanced_opengl/11.anti_aliasing_offscreen/anti_aliasing_offscreen.cpp index 12da46a..1ae985a 100644 --- a/src/4.advanced_opengl/11.anti_aliasing_offscreen/anti_aliasing_offscreen.cpp +++ b/src/4.advanced_opengl/11.anti_aliasing_offscreen/anti_aliasing_offscreen.cpp @@ -44,13 +44,13 @@ int main() // glfw window creation // -------------------- GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL); - glfwMakeContextCurrent(window); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } + glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwSetCursorPosCallback(window, mouse_callback); glfwSetScrollCallback(window, scroll_callback); @@ -224,7 +224,7 @@ int main() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); - // Set transformation matrices + // set transformation matrices shader.use(); glm::mat4 projection = glm::perspective(camera.Zoom, (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 1000.0f); shader.setMat4("projection", projection); @@ -245,11 +245,11 @@ int main() glClear(GL_COLOR_BUFFER_BIT); glDisable(GL_DEPTH_TEST); - // Draw Screen quad + // draw Screen quad screenShader.use(); glBindVertexArray(quadVAO); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, screenTexture); // use the now resolved color attachment as the quad's texture + glBindTexture(GL_TEXTURE_2D, screenTexture); // use the now resolved color attachment as the quad's texture glDrawArrays(GL_TRIANGLES, 0, 6); // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.) @@ -269,7 +269,6 @@ void processInput(GLFWwindow *window) if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); - float cameraSpeed = 2.5 * deltaTime; if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) camera.ProcessKeyboard(FORWARD, deltaTime); if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) @@ -289,7 +288,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height) glViewport(0, 0, width, height); } - // glfw: whenever the mouse moves, this callback is called // ------------------------------------------------------- void mouse_callback(GLFWwindow* window, double xpos, double ypos) diff --git a/src/4.advanced_opengl/2.stencil_testing/stencil_testing.cpp b/src/4.advanced_opengl/2.stencil_testing/stencil_testing.cpp index 26cd2ed..eb7e07d 100644 --- a/src/4.advanced_opengl/2.stencil_testing/stencil_testing.cpp +++ b/src/4.advanced_opengl/2.stencil_testing/stencil_testing.cpp @@ -45,13 +45,13 @@ int main() // glfw window creation // -------------------- GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL); - glfwMakeContextCurrent(window); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } + glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwSetCursorPosCallback(window, mouse_callback); glfwSetScrollCallback(window, scroll_callback); @@ -277,7 +277,6 @@ void processInput(GLFWwindow *window) if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); - float cameraSpeed = 2.5 * deltaTime; if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) camera.ProcessKeyboard(FORWARD, deltaTime); if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) @@ -297,7 +296,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height) glViewport(0, 0, width, height); } - // glfw: whenever the mouse moves, this callback is called // ------------------------------------------------------- void mouse_callback(GLFWwindow* window, double xpos, double ypos) diff --git a/src/4.advanced_opengl/3.1.blending_discard/3.1.blending.vs b/src/4.advanced_opengl/3.1.blending_discard/3.1.blending.vs index 193634c..de5deb0 100644 --- a/src/4.advanced_opengl/3.1.blending_discard/3.1.blending.vs +++ b/src/4.advanced_opengl/3.1.blending_discard/3.1.blending.vs @@ -11,5 +11,5 @@ uniform mat4 projection; void main() { TexCoords = aTexCoords; - gl_Position = projection * view * model * vec4(aPos, 1.0f); + gl_Position = projection * view * model * vec4(aPos, 1.0); } \ No newline at end of file diff --git a/src/4.advanced_opengl/3.1.blending_discard/blending_discard.cpp b/src/4.advanced_opengl/3.1.blending_discard/blending_discard.cpp index 7acca1d..509fe43 100644 --- a/src/4.advanced_opengl/3.1.blending_discard/blending_discard.cpp +++ b/src/4.advanced_opengl/3.1.blending_discard/blending_discard.cpp @@ -45,13 +45,13 @@ int main() // glfw window creation // -------------------- GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL); - glfwMakeContextCurrent(window); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } + glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwSetCursorPosCallback(window, mouse_callback); glfwSetScrollCallback(window, scroll_callback); @@ -277,7 +277,6 @@ void processInput(GLFWwindow *window) if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); - float cameraSpeed = 2.5 * deltaTime; if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) camera.ProcessKeyboard(FORWARD, deltaTime); if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) @@ -297,7 +296,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height) glViewport(0, 0, width, height); } - // glfw: whenever the mouse moves, this callback is called // ------------------------------------------------------- void mouse_callback(GLFWwindow* window, double xpos, double ypos) diff --git a/src/4.advanced_opengl/3.2.blending_sort/3.2.blending.vs b/src/4.advanced_opengl/3.2.blending_sort/3.2.blending.vs index c25148d..de5deb0 100644 --- a/src/4.advanced_opengl/3.2.blending_sort/3.2.blending.vs +++ b/src/4.advanced_opengl/3.2.blending_sort/3.2.blending.vs @@ -1,14 +1,15 @@ #version 330 core -out vec4 FragColor; +layout (location = 0) in vec3 aPos; +layout (location = 1) in vec2 aTexCoords; -in vec2 TexCoords; +out vec2 TexCoords; -uniform sampler2D texture1; +uniform mat4 model; +uniform mat4 view; +uniform mat4 projection; void main() -{ - vec4 texColor = texture(texture1, TexCoords); - if(texColor.a < 0.1) - discard; - FragColor = texColor; +{ + TexCoords = aTexCoords; + gl_Position = projection * view * model * vec4(aPos, 1.0); } \ No newline at end of file diff --git a/src/4.advanced_opengl/3.2.blending_sort/blending_sorted.cpp b/src/4.advanced_opengl/3.2.blending_sort/blending_sorted.cpp index 338d5b8..8d7b6c2 100644 --- a/src/4.advanced_opengl/3.2.blending_sort/blending_sorted.cpp +++ b/src/4.advanced_opengl/3.2.blending_sort/blending_sorted.cpp @@ -45,13 +45,13 @@ int main() // glfw window creation // -------------------- GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL); - glfwMakeContextCurrent(window); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } + glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwSetCursorPosCallback(window, mouse_callback); glfwSetScrollCallback(window, scroll_callback); @@ -75,7 +75,7 @@ int main() // build and compile shaders // ------------------------- - Shader shader("3.1.blending.vs", "3.1.blending.fs"); + Shader shader("3.2.blending.vs", "3.2.blending.fs"); // set up vertex data (and buffer(s)) and configure vertex attributes // ------------------------------------------------------------------ @@ -288,7 +288,6 @@ void processInput(GLFWwindow *window) if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); - float cameraSpeed = 2.5 * deltaTime; if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) camera.ProcessKeyboard(FORWARD, deltaTime); if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) @@ -308,7 +307,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height) glViewport(0, 0, width, height); } - // glfw: whenever the mouse moves, this callback is called // ------------------------------------------------------- void mouse_callback(GLFWwindow* window, double xpos, double ypos) diff --git a/src/4.advanced_opengl/5.1.framebuffers/framebuffers.cpp b/src/4.advanced_opengl/5.1.framebuffers/framebuffers.cpp index 712d53e..dcadbe7 100644 --- a/src/4.advanced_opengl/5.1.framebuffers/framebuffers.cpp +++ b/src/4.advanced_opengl/5.1.framebuffers/framebuffers.cpp @@ -45,13 +45,13 @@ int main() // glfw window creation // -------------------- GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL); - glfwMakeContextCurrent(window); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } + glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwSetCursorPosCallback(window, mouse_callback); glfwSetScrollCallback(window, scroll_callback); @@ -304,7 +304,6 @@ void processInput(GLFWwindow *window) if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); - float cameraSpeed = 2.5 * deltaTime; if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) camera.ProcessKeyboard(FORWARD, deltaTime); if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) @@ -324,7 +323,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height) glViewport(0, 0, width, height); } - // glfw: whenever the mouse moves, this callback is called // ------------------------------------------------------- void mouse_callback(GLFWwindow* window, double xpos, double ypos) diff --git a/src/4.advanced_opengl/5.2.framebuffers_exercise1/5.2.framebuffers.fs b/src/4.advanced_opengl/5.2.framebuffers_exercise1/5.2.framebuffers.fs new file mode 100644 index 0000000..b342078 --- /dev/null +++ b/src/4.advanced_opengl/5.2.framebuffers_exercise1/5.2.framebuffers.fs @@ -0,0 +1,11 @@ +#version 330 core +out vec4 FragColor; + +in vec2 TexCoords; + +uniform sampler2D texture1; + +void main() +{ + FragColor = texture(texture1, TexCoords); +} \ No newline at end of file diff --git a/src/4.advanced_opengl/5.2.framebuffers_exercise1/5.2.framebuffers.vs b/src/4.advanced_opengl/5.2.framebuffers_exercise1/5.2.framebuffers.vs new file mode 100644 index 0000000..ddede39 --- /dev/null +++ b/src/4.advanced_opengl/5.2.framebuffers_exercise1/5.2.framebuffers.vs @@ -0,0 +1,15 @@ +#version 330 core +layout (location = 0) in vec3 aPos; +layout (location = 1) in vec2 aTexCoords; + +out vec2 TexCoords; + +uniform mat4 model; +uniform mat4 view; +uniform mat4 projection; + +void main() +{ + TexCoords = aTexCoords; + gl_Position = projection * view * model * vec4(aPos, 1.0); +} \ No newline at end of file diff --git a/src/4.advanced_opengl/5.2.framebuffers_exercise1/5.2.framebuffers_screen.fs b/src/4.advanced_opengl/5.2.framebuffers_exercise1/5.2.framebuffers_screen.fs new file mode 100644 index 0000000..a23a2a8 --- /dev/null +++ b/src/4.advanced_opengl/5.2.framebuffers_exercise1/5.2.framebuffers_screen.fs @@ -0,0 +1,12 @@ +#version 330 core +out vec4 FragColor; + +in vec2 TexCoords; + +uniform sampler2D screenTexture; + +void main() +{ + vec3 col = texture(screenTexture, TexCoords).rgb; + FragColor = vec4(col, 1.0); +} \ No newline at end of file diff --git a/src/4.advanced_opengl/5.2.framebuffers_exercise1/5.2.framebuffers_screen.vs b/src/4.advanced_opengl/5.2.framebuffers_exercise1/5.2.framebuffers_screen.vs new file mode 100644 index 0000000..1376b62 --- /dev/null +++ b/src/4.advanced_opengl/5.2.framebuffers_exercise1/5.2.framebuffers_screen.vs @@ -0,0 +1,11 @@ +#version 330 core +layout (location = 0) in vec2 aPos; +layout (location = 1) in vec2 aTexCoords; + +out vec2 TexCoords; + +void main() +{ + TexCoords = aTexCoords; + gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0); +} \ No newline at end of file diff --git a/src/4.advanced_opengl/5.2.framebuffers_exercise1/framebuffers_exercise1.cpp b/src/4.advanced_opengl/5.2.framebuffers_exercise1/framebuffers_exercise1.cpp index 235baf4..b7e80a3 100644 --- a/src/4.advanced_opengl/5.2.framebuffers_exercise1/framebuffers_exercise1.cpp +++ b/src/4.advanced_opengl/5.2.framebuffers_exercise1/framebuffers_exercise1.cpp @@ -45,13 +45,13 @@ int main() // glfw window creation // -------------------- GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL); - glfwMakeContextCurrent(window); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } + glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwSetCursorPosCallback(window, mouse_callback); glfwSetScrollCallback(window, scroll_callback); @@ -73,8 +73,8 @@ int main() // build and compile shaders // ------------------------- - Shader shader("5.1.framebuffers.vs", "5.1.framebuffers.fs"); - Shader screenShader("5.1.framebuffers_screen.vs", "5.1.framebuffers_screen.fs"); + Shader shader("5.2.framebuffers.vs", "5.2.framebuffers.fs"); + Shader screenShader("5.2.framebuffers_screen.vs", "5.2.framebuffers_screen.fs"); // set up vertex data (and buffer(s)) and configure vertex attributes // ------------------------------------------------------------------ @@ -338,7 +338,6 @@ void processInput(GLFWwindow *window) if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); - float cameraSpeed = 2.5 * deltaTime; if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) camera.ProcessKeyboard(FORWARD, deltaTime); if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) @@ -358,7 +357,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height) glViewport(0, 0, width, height); } - // glfw: whenever the mouse moves, this callback is called // ------------------------------------------------------- void mouse_callback(GLFWwindow* window, double xpos, double ypos) diff --git a/src/4.advanced_opengl/6.1.cubemaps_skybox/6.1.cubemaps.vs b/src/4.advanced_opengl/6.1.cubemaps_skybox/6.1.cubemaps.vs index 95cb343..ddede39 100644 --- a/src/4.advanced_opengl/6.1.cubemaps_skybox/6.1.cubemaps.vs +++ b/src/4.advanced_opengl/6.1.cubemaps_skybox/6.1.cubemaps.vs @@ -11,5 +11,5 @@ uniform mat4 projection; void main() { TexCoords = aTexCoords; - gl_Position = projection * view * model * vec4(aPos, 1.0f); + gl_Position = projection * view * model * vec4(aPos, 1.0); } \ No newline at end of file diff --git a/src/4.advanced_opengl/6.1.cubemaps_skybox/cubemaps_skybox.cpp b/src/4.advanced_opengl/6.1.cubemaps_skybox/cubemaps_skybox.cpp index 0ab5fff..6d95a94 100644 --- a/src/4.advanced_opengl/6.1.cubemaps_skybox/cubemaps_skybox.cpp +++ b/src/4.advanced_opengl/6.1.cubemaps_skybox/cubemaps_skybox.cpp @@ -46,13 +46,13 @@ int main() // glfw window creation // -------------------- GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL); - glfwMakeContextCurrent(window); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } + glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwSetCursorPosCallback(window, mouse_callback); glfwSetScrollCallback(window, scroll_callback); @@ -284,7 +284,6 @@ void processInput(GLFWwindow *window) if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); - float cameraSpeed = 2.5 * deltaTime; if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) camera.ProcessKeyboard(FORWARD, deltaTime); if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) @@ -304,7 +303,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height) glViewport(0, 0, width, height); } - // glfw: whenever the mouse moves, this callback is called // ------------------------------------------------------- void mouse_callback(GLFWwindow* window, double xpos, double ypos) @@ -386,10 +384,10 @@ unsigned int loadCubemap(vector faces) glGenTextures(1, &textureID); glBindTexture(GL_TEXTURE_CUBE_MAP, textureID); - int width, height, nrComponents; + int width, height, nrChannels; for (unsigned int i = 0; i < faces.size(); i++) { - unsigned char *data = stbi_load(faces[i].c_str(), &width, &height, &nrComponents, 0); + unsigned char *data = stbi_load(faces[i].c_str(), &width, &height, &nrChannels, 0); if (data) { glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); diff --git a/src/4.advanced_opengl/6.2.cubemaps_environment_mapping/6.2.skybox.fs b/src/4.advanced_opengl/6.2.cubemaps_environment_mapping/6.2.skybox.fs new file mode 100644 index 0000000..5d0e53e --- /dev/null +++ b/src/4.advanced_opengl/6.2.cubemaps_environment_mapping/6.2.skybox.fs @@ -0,0 +1,11 @@ +#version 330 core +out vec4 FragColor; + +in vec3 TexCoords; + +uniform samplerCube skybox; + +void main() +{ + FragColor = texture(skybox, TexCoords); +} \ No newline at end of file diff --git a/src/4.advanced_opengl/6.2.cubemaps_environment_mapping/6.2.skybox.vs b/src/4.advanced_opengl/6.2.cubemaps_environment_mapping/6.2.skybox.vs new file mode 100644 index 0000000..0d20a97 --- /dev/null +++ b/src/4.advanced_opengl/6.2.cubemaps_environment_mapping/6.2.skybox.vs @@ -0,0 +1,14 @@ +#version 330 core +layout (location = 0) in vec3 aPos; + +out vec3 TexCoords; + +uniform mat4 projection; +uniform mat4 view; + +void main() +{ + TexCoords = aPos; + vec4 pos = projection * view * vec4(aPos, 1.0); + gl_Position = pos.xyww; +} \ No newline at end of file diff --git a/src/4.advanced_opengl/6.2.cubemaps_environment_mapping/cubemaps_environment_mapping.cpp b/src/4.advanced_opengl/6.2.cubemaps_environment_mapping/cubemaps_environment_mapping.cpp index a9946dd..2edeb16 100644 --- a/src/4.advanced_opengl/6.2.cubemaps_environment_mapping/cubemaps_environment_mapping.cpp +++ b/src/4.advanced_opengl/6.2.cubemaps_environment_mapping/cubemaps_environment_mapping.cpp @@ -46,13 +46,13 @@ int main() // glfw window creation // -------------------- GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL); - glfwMakeContextCurrent(window); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } + glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwSetCursorPosCallback(window, mouse_callback); glfwSetScrollCallback(window, scroll_callback); @@ -75,7 +75,7 @@ int main() // build and compile shaders // ------------------------- Shader shader("6.2.cubemaps.vs", "6.2.cubemaps.fs"); - Shader skyboxShader("6.1.skybox.vs", "6.1.skybox.fs"); + Shader skyboxShader("6.2.skybox.vs", "6.2.skybox.fs"); // set up vertex data (and buffer(s)) and configure vertex attributes // ------------------------------------------------------------------ @@ -283,7 +283,6 @@ void processInput(GLFWwindow *window) if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); - float cameraSpeed = 2.5 * deltaTime; if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) camera.ProcessKeyboard(FORWARD, deltaTime); if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) @@ -303,7 +302,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height) glViewport(0, 0, width, height); } - // glfw: whenever the mouse moves, this callback is called // ------------------------------------------------------- void mouse_callback(GLFWwindow* window, double xpos, double ypos) diff --git a/src/4.advanced_opengl/8.advanced_glsl_ubo/advanced_glsl_ubo.cpp b/src/4.advanced_opengl/8.advanced_glsl_ubo/advanced_glsl_ubo.cpp index fe868ab..aeac002 100644 --- a/src/4.advanced_opengl/8.advanced_glsl_ubo/advanced_glsl_ubo.cpp +++ b/src/4.advanced_opengl/8.advanced_glsl_ubo/advanced_glsl_ubo.cpp @@ -43,13 +43,13 @@ int main() // glfw window creation // -------------------- GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL); - glfwMakeContextCurrent(window); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } + glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwSetCursorPosCallback(window, mouse_callback); @@ -232,7 +232,6 @@ void processInput(GLFWwindow *window) if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); - float cameraSpeed = 2.5 * deltaTime; if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) camera.ProcessKeyboard(FORWARD, deltaTime); if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) @@ -252,7 +251,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height) glViewport(0, 0, width, height); } - // glfw: whenever the mouse moves, this callback is called // ------------------------------------------------------- void mouse_callback(GLFWwindow* window, double xpos, double ypos) diff --git a/src/4.advanced_opengl/9.1.geometry_shader_houses/geometry_shader_houses.cpp b/src/4.advanced_opengl/9.1.geometry_shader_houses/geometry_shader_houses.cpp index c3be032..ada4306 100644 --- a/src/4.advanced_opengl/9.1.geometry_shader_houses/geometry_shader_houses.cpp +++ b/src/4.advanced_opengl/9.1.geometry_shader_houses/geometry_shader_houses.cpp @@ -24,13 +24,13 @@ int main() // glfw window creation // -------------------- GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL); - glfwMakeContextCurrent(window); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } + glfwMakeContextCurrent(window); // glad: load all OpenGL function pointers // --------------------------------------- diff --git a/src/4.advanced_opengl/9.2.geometry_shader_exploding/geometry_shader_exploding.cpp b/src/4.advanced_opengl/9.2.geometry_shader_exploding/geometry_shader_exploding.cpp index 215a1b7..a257809 100644 --- a/src/4.advanced_opengl/9.2.geometry_shader_exploding/geometry_shader_exploding.cpp +++ b/src/4.advanced_opengl/9.2.geometry_shader_exploding/geometry_shader_exploding.cpp @@ -44,13 +44,13 @@ int main() // glfw window creation // -------------------- GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL); - glfwMakeContextCurrent(window); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } + glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwSetCursorPosCallback(window, mouse_callback); glfwSetScrollCallback(window, scroll_callback); @@ -129,7 +129,6 @@ void processInput(GLFWwindow *window) if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); - float cameraSpeed = 2.5 * deltaTime; if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) camera.ProcessKeyboard(FORWARD, deltaTime); if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) @@ -149,7 +148,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height) glViewport(0, 0, width, height); } - // glfw: whenever the mouse moves, this callback is called // ------------------------------------------------------- void mouse_callback(GLFWwindow* window, double xpos, double ypos) diff --git a/src/4.advanced_opengl/9.3.geometry_shader_normals/normal_visualization.cpp b/src/4.advanced_opengl/9.3.geometry_shader_normals/normal_visualization.cpp index bcc19a1..449bd43 100644 --- a/src/4.advanced_opengl/9.3.geometry_shader_normals/normal_visualization.cpp +++ b/src/4.advanced_opengl/9.3.geometry_shader_normals/normal_visualization.cpp @@ -44,13 +44,13 @@ int main() // glfw window creation // -------------------- GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL); - glfwMakeContextCurrent(window); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } + glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwSetCursorPosCallback(window, mouse_callback); glfwSetScrollCallback(window, scroll_callback); @@ -135,7 +135,6 @@ void processInput(GLFWwindow *window) if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); - float cameraSpeed = 2.5 * deltaTime; if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) camera.ProcessKeyboard(FORWARD, deltaTime); if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) @@ -155,7 +154,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height) glViewport(0, 0, width, height); } - // glfw: whenever the mouse moves, this callback is called // ------------------------------------------------------- void mouse_callback(GLFWwindow* window, double xpos, double ypos)