mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-30 20:13:22 +08:00
Code and content re-work: advanced lighting.
This commit is contained in:
@@ -47,13 +47,13 @@ int main()
|
|||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
glfwSetCursorPosCallback(window, mouse_callback);
|
glfwSetCursorPosCallback(window, mouse_callback);
|
||||||
glfwSetScrollCallback(window, scroll_callback);
|
glfwSetScrollCallback(window, scroll_callback);
|
||||||
@@ -178,7 +178,6 @@ void processInput(GLFWwindow *window)
|
|||||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||||
glfwSetWindowShouldClose(window, true);
|
glfwSetWindowShouldClose(window, true);
|
||||||
|
|
||||||
float cameraSpeed = 2.5 * deltaTime;
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||||
camera.ProcessKeyboard(FORWARD, deltaTime);
|
camera.ProcessKeyboard(FORWARD, deltaTime);
|
||||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||||
@@ -208,7 +207,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
|||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// glfw: whenever the mouse moves, this callback is called
|
// glfw: whenever the mouse moves, this callback is called
|
||||||
// -------------------------------------------------------
|
// -------------------------------------------------------
|
||||||
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
||||||
|
|||||||
@@ -47,13 +47,13 @@ int main()
|
|||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
glfwSetCursorPosCallback(window, mouse_callback);
|
glfwSetCursorPosCallback(window, mouse_callback);
|
||||||
glfwSetScrollCallback(window, scroll_callback);
|
glfwSetScrollCallback(window, scroll_callback);
|
||||||
@@ -191,7 +191,6 @@ void processInput(GLFWwindow *window)
|
|||||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||||
glfwSetWindowShouldClose(window, true);
|
glfwSetWindowShouldClose(window, true);
|
||||||
|
|
||||||
float cameraSpeed = 2.5 * deltaTime;
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||||
camera.ProcessKeyboard(FORWARD, deltaTime);
|
camera.ProcessKeyboard(FORWARD, deltaTime);
|
||||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||||
@@ -221,7 +220,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
|||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// glfw: whenever the mouse moves, this callback is called
|
// glfw: whenever the mouse moves, this callback is called
|
||||||
// -------------------------------------------------------
|
// -------------------------------------------------------
|
||||||
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
||||||
|
|||||||
@@ -51,13 +51,13 @@ int main()
|
|||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
glfwSetCursorPosCallback(window, mouse_callback);
|
glfwSetCursorPosCallback(window, mouse_callback);
|
||||||
glfwSetScrollCallback(window, scroll_callback);
|
glfwSetScrollCallback(window, scroll_callback);
|
||||||
@@ -353,7 +353,6 @@ void processInput(GLFWwindow *window)
|
|||||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||||
glfwSetWindowShouldClose(window, true);
|
glfwSetWindowShouldClose(window, true);
|
||||||
|
|
||||||
float cameraSpeed = 2.5 * deltaTime;
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||||
camera.ProcessKeyboard(FORWARD, deltaTime);
|
camera.ProcessKeyboard(FORWARD, deltaTime);
|
||||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||||
@@ -373,7 +372,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
|||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// glfw: whenever the mouse moves, this callback is called
|
// glfw: whenever the mouse moves, this callback is called
|
||||||
// -------------------------------------------------------
|
// -------------------------------------------------------
|
||||||
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
||||||
|
|||||||
@@ -51,13 +51,13 @@ int main()
|
|||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
glfwSetCursorPosCallback(window, mouse_callback);
|
glfwSetCursorPosCallback(window, mouse_callback);
|
||||||
glfwSetScrollCallback(window, scroll_callback);
|
glfwSetScrollCallback(window, scroll_callback);
|
||||||
@@ -80,8 +80,8 @@ int main()
|
|||||||
// build and compile shaders
|
// build and compile shaders
|
||||||
// -------------------------
|
// -------------------------
|
||||||
Shader shader("3.1.2.shadow_mapping.vs", "3.1.2.shadow_mapping.fs");
|
Shader shader("3.1.2.shadow_mapping.vs", "3.1.2.shadow_mapping.fs");
|
||||||
Shader simpleDepthShader("3.1.1.shadow_mapping_depth.vs", "3.1.1.shadow_mapping_depth.fs");
|
Shader simpleDepthShader("3.1.2.shadow_mapping_depth.vs", "3.1.2.shadow_mapping_depth.fs");
|
||||||
Shader debugDepthQuad("3.1.1.debug_quad.vs", "3.1.1.debug_quad_depth.fs");
|
Shader debugDepthQuad("3.1.2.debug_quad.vs", "3.1.2.debug_quad_depth.fs");
|
||||||
|
|
||||||
// set up vertex data (and buffer(s)) and configure vertex attributes
|
// set up vertex data (and buffer(s)) and configure vertex attributes
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
|
|||||||
@@ -51,13 +51,13 @@ int main()
|
|||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
glfwSetCursorPosCallback(window, mouse_callback);
|
glfwSetCursorPosCallback(window, mouse_callback);
|
||||||
glfwSetScrollCallback(window, scroll_callback);
|
glfwSetScrollCallback(window, scroll_callback);
|
||||||
@@ -80,8 +80,8 @@ int main()
|
|||||||
// build and compile shaders
|
// build and compile shaders
|
||||||
// -------------------------
|
// -------------------------
|
||||||
Shader shader("3.1.3.shadow_mapping.vs", "3.1.3.shadow_mapping.fs");
|
Shader shader("3.1.3.shadow_mapping.vs", "3.1.3.shadow_mapping.fs");
|
||||||
Shader simpleDepthShader("3.1.1.shadow_mapping_depth.vs", "3.1.1.shadow_mapping_depth.fs");
|
Shader simpleDepthShader("3.1.3.shadow_mapping_depth.vs", "3.1.3.shadow_mapping_depth.fs");
|
||||||
Shader debugDepthQuad("3.1.1.debug_quad.vs", "3.1.1.debug_quad_depth.fs");
|
Shader debugDepthQuad("3.1.3.debug_quad.vs", "3.1.3.debug_quad_depth.fs");
|
||||||
|
|
||||||
// set up vertex data (and buffer(s)) and configure vertex attributes
|
// set up vertex data (and buffer(s)) and configure vertex attributes
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
@@ -128,7 +128,7 @@ int main()
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||||
GLfloat borderColor[] = { 1.0, 1.0, 1.0, 1.0 };
|
float borderColor[] = { 1.0, 1.0, 1.0, 1.0 };
|
||||||
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
|
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
|
||||||
// attach depth texture as FBO's depth buffer
|
// attach depth texture as FBO's depth buffer
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
|
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
|
||||||
@@ -384,7 +384,6 @@ void processInput(GLFWwindow *window)
|
|||||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||||
glfwSetWindowShouldClose(window, true);
|
glfwSetWindowShouldClose(window, true);
|
||||||
|
|
||||||
float cameraSpeed = 2.5 * deltaTime;
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||||
camera.ProcessKeyboard(FORWARD, deltaTime);
|
camera.ProcessKeyboard(FORWARD, deltaTime);
|
||||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||||
@@ -404,7 +403,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
|||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// glfw: whenever the mouse moves, this callback is called
|
// glfw: whenever the mouse moves, this callback is called
|
||||||
// -------------------------------------------------------
|
// -------------------------------------------------------
|
||||||
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
||||||
|
|||||||
@@ -49,13 +49,13 @@ int main()
|
|||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
glfwSetCursorPosCallback(window, mouse_callback);
|
glfwSetCursorPosCallback(window, mouse_callback);
|
||||||
glfwSetScrollCallback(window, scroll_callback);
|
glfwSetScrollCallback(window, scroll_callback);
|
||||||
@@ -321,7 +321,6 @@ void processInput(GLFWwindow *window)
|
|||||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||||
glfwSetWindowShouldClose(window, true);
|
glfwSetWindowShouldClose(window, true);
|
||||||
|
|
||||||
float cameraSpeed = 2.5 * deltaTime;
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||||
camera.ProcessKeyboard(FORWARD, deltaTime);
|
camera.ProcessKeyboard(FORWARD, deltaTime);
|
||||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||||
@@ -351,7 +350,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
|||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// glfw: whenever the mouse moves, this callback is called
|
// glfw: whenever the mouse moves, this callback is called
|
||||||
// -------------------------------------------------------
|
// -------------------------------------------------------
|
||||||
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
||||||
|
|||||||
@@ -49,13 +49,13 @@ int main()
|
|||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
glfwSetCursorPosCallback(window, mouse_callback);
|
glfwSetCursorPosCallback(window, mouse_callback);
|
||||||
glfwSetScrollCallback(window, scroll_callback);
|
glfwSetScrollCallback(window, scroll_callback);
|
||||||
@@ -79,7 +79,7 @@ int main()
|
|||||||
// build and compile shaders
|
// build and compile shaders
|
||||||
// -------------------------
|
// -------------------------
|
||||||
Shader shader("3.2.2.point_shadows.vs", "3.2.2.point_shadows.fs");
|
Shader shader("3.2.2.point_shadows.vs", "3.2.2.point_shadows.fs");
|
||||||
Shader simpleDepthShader("3.2.1.point_shadows_depth.vs", "3.2.1.point_shadows_depth.fs", "3.2.1.point_shadows_depth.gs");
|
Shader simpleDepthShader("3.2.2.point_shadows_depth.vs", "3.2.2.point_shadows_depth.fs", "3.2.2.point_shadows_depth.gs");
|
||||||
|
|
||||||
// load textures
|
// load textures
|
||||||
// -------------
|
// -------------
|
||||||
@@ -321,7 +321,6 @@ void processInput(GLFWwindow *window)
|
|||||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||||
glfwSetWindowShouldClose(window, true);
|
glfwSetWindowShouldClose(window, true);
|
||||||
|
|
||||||
float cameraSpeed = 2.5 * deltaTime;
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||||
camera.ProcessKeyboard(FORWARD, deltaTime);
|
camera.ProcessKeyboard(FORWARD, deltaTime);
|
||||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||||
@@ -351,7 +350,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
|||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// glfw: whenever the mouse moves, this callback is called
|
// glfw: whenever the mouse moves, this callback is called
|
||||||
// -------------------------------------------------------
|
// -------------------------------------------------------
|
||||||
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
||||||
|
|||||||
@@ -46,13 +46,13 @@ int main()
|
|||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
glfwSetCursorPosCallback(window, mouse_callback);
|
glfwSetCursorPosCallback(window, mouse_callback);
|
||||||
glfwSetScrollCallback(window, scroll_callback);
|
glfwSetScrollCallback(window, scroll_callback);
|
||||||
@@ -248,7 +248,6 @@ void processInput(GLFWwindow *window)
|
|||||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||||
glfwSetWindowShouldClose(window, true);
|
glfwSetWindowShouldClose(window, true);
|
||||||
|
|
||||||
float cameraSpeed = 2.5 * deltaTime;
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||||
camera.ProcessKeyboard(FORWARD, deltaTime);
|
camera.ProcessKeyboard(FORWARD, deltaTime);
|
||||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||||
@@ -268,7 +267,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
|||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// glfw: whenever the mouse moves, this callback is called
|
// glfw: whenever the mouse moves, this callback is called
|
||||||
// -------------------------------------------------------
|
// -------------------------------------------------------
|
||||||
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
||||||
|
|||||||
@@ -47,13 +47,13 @@ int main()
|
|||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
glfwSetCursorPosCallback(window, mouse_callback);
|
glfwSetCursorPosCallback(window, mouse_callback);
|
||||||
glfwSetScrollCallback(window, scroll_callback);
|
glfwSetScrollCallback(window, scroll_callback);
|
||||||
@@ -186,7 +186,7 @@ void renderQuad()
|
|||||||
glm::vec2 deltaUV1 = uv2 - uv1;
|
glm::vec2 deltaUV1 = uv2 - uv1;
|
||||||
glm::vec2 deltaUV2 = uv3 - uv1;
|
glm::vec2 deltaUV2 = uv3 - uv1;
|
||||||
|
|
||||||
GLfloat f = 1.0f / (deltaUV1.x * deltaUV2.y - deltaUV2.x * deltaUV1.y);
|
float f = 1.0f / (deltaUV1.x * deltaUV2.y - deltaUV2.x * deltaUV1.y);
|
||||||
|
|
||||||
tangent1.x = f * (deltaUV2.y * edge1.x - deltaUV1.y * edge2.x);
|
tangent1.x = f * (deltaUV2.y * edge1.x - deltaUV1.y * edge2.x);
|
||||||
tangent1.y = f * (deltaUV2.y * edge1.y - deltaUV1.y * edge2.y);
|
tangent1.y = f * (deltaUV2.y * edge1.y - deltaUV1.y * edge2.y);
|
||||||
@@ -258,7 +258,6 @@ void processInput(GLFWwindow *window)
|
|||||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||||
glfwSetWindowShouldClose(window, true);
|
glfwSetWindowShouldClose(window, true);
|
||||||
|
|
||||||
float cameraSpeed = 2.5 * deltaTime;
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||||
camera.ProcessKeyboard(FORWARD, deltaTime);
|
camera.ProcessKeyboard(FORWARD, deltaTime);
|
||||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||||
@@ -293,7 +292,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
|||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// glfw: whenever the mouse moves, this callback is called
|
// glfw: whenever the mouse moves, this callback is called
|
||||||
// -------------------------------------------------------
|
// -------------------------------------------------------
|
||||||
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
||||||
|
|||||||
@@ -47,13 +47,13 @@ int main()
|
|||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
glfwSetCursorPosCallback(window, mouse_callback);
|
glfwSetCursorPosCallback(window, mouse_callback);
|
||||||
glfwSetScrollCallback(window, scroll_callback);
|
glfwSetScrollCallback(window, scroll_callback);
|
||||||
@@ -186,7 +186,7 @@ void renderQuad()
|
|||||||
glm::vec2 deltaUV1 = uv2 - uv1;
|
glm::vec2 deltaUV1 = uv2 - uv1;
|
||||||
glm::vec2 deltaUV2 = uv3 - uv1;
|
glm::vec2 deltaUV2 = uv3 - uv1;
|
||||||
|
|
||||||
GLfloat f = 1.0f / (deltaUV1.x * deltaUV2.y - deltaUV2.x * deltaUV1.y);
|
float f = 1.0f / (deltaUV1.x * deltaUV2.y - deltaUV2.x * deltaUV1.y);
|
||||||
|
|
||||||
tangent1.x = f * (deltaUV2.y * edge1.x - deltaUV1.y * edge2.x);
|
tangent1.x = f * (deltaUV2.y * edge1.x - deltaUV1.y * edge2.x);
|
||||||
tangent1.y = f * (deltaUV2.y * edge1.y - deltaUV1.y * edge2.y);
|
tangent1.y = f * (deltaUV2.y * edge1.y - deltaUV1.y * edge2.y);
|
||||||
@@ -258,7 +258,6 @@ void processInput(GLFWwindow *window)
|
|||||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||||
glfwSetWindowShouldClose(window, true);
|
glfwSetWindowShouldClose(window, true);
|
||||||
|
|
||||||
float cameraSpeed = 2.5 * deltaTime;
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||||
camera.ProcessKeyboard(FORWARD, deltaTime);
|
camera.ProcessKeyboard(FORWARD, deltaTime);
|
||||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||||
@@ -293,7 +292,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
|||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// glfw: whenever the mouse moves, this callback is called
|
// glfw: whenever the mouse moves, this callback is called
|
||||||
// -------------------------------------------------------
|
// -------------------------------------------------------
|
||||||
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
||||||
|
|||||||
@@ -47,13 +47,13 @@ int main()
|
|||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
glfwSetCursorPosCallback(window, mouse_callback);
|
glfwSetCursorPosCallback(window, mouse_callback);
|
||||||
glfwSetScrollCallback(window, scroll_callback);
|
glfwSetScrollCallback(window, scroll_callback);
|
||||||
@@ -186,7 +186,7 @@ void renderQuad()
|
|||||||
glm::vec2 deltaUV1 = uv2 - uv1;
|
glm::vec2 deltaUV1 = uv2 - uv1;
|
||||||
glm::vec2 deltaUV2 = uv3 - uv1;
|
glm::vec2 deltaUV2 = uv3 - uv1;
|
||||||
|
|
||||||
GLfloat f = 1.0f / (deltaUV1.x * deltaUV2.y - deltaUV2.x * deltaUV1.y);
|
float f = 1.0f / (deltaUV1.x * deltaUV2.y - deltaUV2.x * deltaUV1.y);
|
||||||
|
|
||||||
tangent1.x = f * (deltaUV2.y * edge1.x - deltaUV1.y * edge2.x);
|
tangent1.x = f * (deltaUV2.y * edge1.x - deltaUV1.y * edge2.x);
|
||||||
tangent1.y = f * (deltaUV2.y * edge1.y - deltaUV1.y * edge2.y);
|
tangent1.y = f * (deltaUV2.y * edge1.y - deltaUV1.y * edge2.y);
|
||||||
@@ -258,7 +258,6 @@ void processInput(GLFWwindow *window)
|
|||||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||||
glfwSetWindowShouldClose(window, true);
|
glfwSetWindowShouldClose(window, true);
|
||||||
|
|
||||||
float cameraSpeed = 2.5 * deltaTime;
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||||
camera.ProcessKeyboard(FORWARD, deltaTime);
|
camera.ProcessKeyboard(FORWARD, deltaTime);
|
||||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||||
@@ -293,7 +292,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
|||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// glfw: whenever the mouse moves, this callback is called
|
// glfw: whenever the mouse moves, this callback is called
|
||||||
// -------------------------------------------------------
|
// -------------------------------------------------------
|
||||||
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
||||||
|
|||||||
@@ -50,13 +50,13 @@ int main()
|
|||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
glfwSetCursorPosCallback(window, mouse_callback);
|
glfwSetCursorPosCallback(window, mouse_callback);
|
||||||
glfwSetScrollCallback(window, scroll_callback);
|
glfwSetScrollCallback(window, scroll_callback);
|
||||||
@@ -312,7 +312,6 @@ void processInput(GLFWwindow *window)
|
|||||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||||
glfwSetWindowShouldClose(window, true);
|
glfwSetWindowShouldClose(window, true);
|
||||||
|
|
||||||
float cameraSpeed = 2.5 * deltaTime;
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||||
camera.ProcessKeyboard(FORWARD, deltaTime);
|
camera.ProcessKeyboard(FORWARD, deltaTime);
|
||||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||||
@@ -354,7 +353,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
|||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// glfw: whenever the mouse moves, this callback is called
|
// glfw: whenever the mouse moves, this callback is called
|
||||||
// -------------------------------------------------------
|
// -------------------------------------------------------
|
||||||
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ out vec4 FragColor;
|
|||||||
in vec2 TexCoords;
|
in vec2 TexCoords;
|
||||||
|
|
||||||
uniform sampler2D image;
|
uniform sampler2D image;
|
||||||
uniform bool horizontal;
|
|
||||||
|
|
||||||
|
uniform bool horizontal;
|
||||||
uniform float weight[5] = float[] (0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162);
|
uniform float weight[5] = float[] (0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162);
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
|
|||||||
@@ -50,13 +50,13 @@ int main()
|
|||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
glfwSetCursorPosCallback(window, mouse_callback);
|
glfwSetCursorPosCallback(window, mouse_callback);
|
||||||
glfwSetScrollCallback(window, scroll_callback);
|
glfwSetScrollCallback(window, scroll_callback);
|
||||||
@@ -421,7 +421,6 @@ void processInput(GLFWwindow *window)
|
|||||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||||
glfwSetWindowShouldClose(window, true);
|
glfwSetWindowShouldClose(window, true);
|
||||||
|
|
||||||
float cameraSpeed = 2.5 * deltaTime;
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||||
camera.ProcessKeyboard(FORWARD, deltaTime);
|
camera.ProcessKeyboard(FORWARD, deltaTime);
|
||||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||||
@@ -463,7 +462,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
|||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// glfw: whenever the mouse moves, this callback is called
|
// glfw: whenever the mouse moves, this callback is called
|
||||||
// -------------------------------------------------------
|
// -------------------------------------------------------
|
||||||
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
||||||
|
|||||||
@@ -46,13 +46,13 @@ int main()
|
|||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
glfwSetCursorPosCallback(window, mouse_callback);
|
glfwSetCursorPosCallback(window, mouse_callback);
|
||||||
glfwSetScrollCallback(window, scroll_callback);
|
glfwSetScrollCallback(window, scroll_callback);
|
||||||
@@ -376,7 +376,6 @@ void processInput(GLFWwindow *window)
|
|||||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||||
glfwSetWindowShouldClose(window, true);
|
glfwSetWindowShouldClose(window, true);
|
||||||
|
|
||||||
float cameraSpeed = 2.5 * deltaTime;
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||||
camera.ProcessKeyboard(FORWARD, deltaTime);
|
camera.ProcessKeyboard(FORWARD, deltaTime);
|
||||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||||
@@ -396,7 +395,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
|||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// glfw: whenever the mouse moves, this callback is called
|
// glfw: whenever the mouse moves, this callback is called
|
||||||
// -------------------------------------------------------
|
// -------------------------------------------------------
|
||||||
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#version 330 core
|
||||||
|
layout (location = 0) out vec4 FragColor;
|
||||||
|
|
||||||
|
uniform vec3 lightColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
FragColor = vec4(lightColor, 1.0);
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#version 330 core
|
||||||
|
layout (location = 0) in vec3 aPos;
|
||||||
|
layout (location = 1) in vec3 aNormal;
|
||||||
|
layout (location = 2) in vec2 aTexCoords;
|
||||||
|
|
||||||
|
uniform mat4 projection;
|
||||||
|
uniform mat4 view;
|
||||||
|
uniform mat4 model;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = projection * view * model * vec4(aPos, 1.0);
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#version 330 core
|
||||||
|
layout (location = 0) out vec3 gPosition;
|
||||||
|
layout (location = 1) out vec3 gNormal;
|
||||||
|
layout (location = 2) out vec4 gAlbedoSpec;
|
||||||
|
|
||||||
|
in vec2 TexCoords;
|
||||||
|
in vec3 FragPos;
|
||||||
|
in vec3 Normal;
|
||||||
|
|
||||||
|
uniform sampler2D texture_diffuse1;
|
||||||
|
uniform sampler2D texture_specular1;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
// store the fragment position vector in the first gbuffer texture
|
||||||
|
gPosition = FragPos;
|
||||||
|
// also store the per-fragment normals into the gbuffer
|
||||||
|
gNormal = normalize(Normal);
|
||||||
|
// and the diffuse per-fragment color
|
||||||
|
gAlbedoSpec.rgb = texture(texture_diffuse1, TexCoords).rgb;
|
||||||
|
// store specular intensity in gAlbedoSpec's alpha component
|
||||||
|
gAlbedoSpec.a = texture(texture_specular1, TexCoords).r;
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
#version 330 core
|
||||||
|
layout (location = 0) in vec3 aPos;
|
||||||
|
layout (location = 1) in vec3 aNormal;
|
||||||
|
layout (location = 2) in vec2 aTexCoords;
|
||||||
|
|
||||||
|
out vec3 FragPos;
|
||||||
|
out vec2 TexCoords;
|
||||||
|
out vec3 Normal;
|
||||||
|
|
||||||
|
uniform mat4 model;
|
||||||
|
uniform mat4 view;
|
||||||
|
uniform mat4 projection;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec4 worldPos = model * vec4(aPos, 1.0);
|
||||||
|
FragPos = worldPos.xyz;
|
||||||
|
TexCoords = aTexCoords;
|
||||||
|
|
||||||
|
mat3 normalMatrix = transpose(inverse(mat3(model)));
|
||||||
|
Normal = normalMatrix * aNormal;
|
||||||
|
|
||||||
|
gl_Position = projection * view * worldPos;
|
||||||
|
}
|
||||||
@@ -46,13 +46,13 @@ int main()
|
|||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
glfwSetCursorPosCallback(window, mouse_callback);
|
glfwSetCursorPosCallback(window, mouse_callback);
|
||||||
glfwSetScrollCallback(window, scroll_callback);
|
glfwSetScrollCallback(window, scroll_callback);
|
||||||
@@ -74,9 +74,9 @@ int main()
|
|||||||
|
|
||||||
// build and compile shaders
|
// build and compile shaders
|
||||||
// -------------------------
|
// -------------------------
|
||||||
Shader shaderGeometryPass("8.1.g_buffer.vs", "8.1.g_buffer.fs");
|
Shader shaderGeometryPass("8.2.g_buffer.vs", "8.2.g_buffer.fs");
|
||||||
Shader shaderLightingPass("8.2.deferred_shading.vs", "8.2.deferred_shading.fs");
|
Shader shaderLightingPass("8.2.deferred_shading.vs", "8.2.deferred_shading.fs");
|
||||||
Shader shaderLightBox("8.1.deferred_light_box.vs", "8.1.deferred_light_box.fs");
|
Shader shaderLightBox("8.2.deferred_light_box.vs", "8.2.deferred_light_box.fs");
|
||||||
|
|
||||||
// load models
|
// load models
|
||||||
// -----------
|
// -----------
|
||||||
@@ -380,7 +380,6 @@ void processInput(GLFWwindow *window)
|
|||||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||||
glfwSetWindowShouldClose(window, true);
|
glfwSetWindowShouldClose(window, true);
|
||||||
|
|
||||||
float cameraSpeed = 2.5 * deltaTime;
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||||
camera.ProcessKeyboard(FORWARD, deltaTime);
|
camera.ProcessKeyboard(FORWARD, deltaTime);
|
||||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||||
@@ -400,7 +399,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
|||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// glfw: whenever the mouse moves, this callback is called
|
// glfw: whenever the mouse moves, this callback is called
|
||||||
// -------------------------------------------------------
|
// -------------------------------------------------------
|
||||||
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
||||||
|
|||||||
@@ -52,13 +52,13 @@ int main()
|
|||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
glfwSetCursorPosCallback(window, mouse_callback);
|
glfwSetCursorPosCallback(window, mouse_callback);
|
||||||
glfwSetScrollCallback(window, scroll_callback);
|
glfwSetScrollCallback(window, scroll_callback);
|
||||||
@@ -438,7 +438,6 @@ void processInput(GLFWwindow *window)
|
|||||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||||
glfwSetWindowShouldClose(window, true);
|
glfwSetWindowShouldClose(window, true);
|
||||||
|
|
||||||
float cameraSpeed = 2.5 * deltaTime;
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||||
camera.ProcessKeyboard(FORWARD, deltaTime);
|
camera.ProcessKeyboard(FORWARD, deltaTime);
|
||||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||||
@@ -458,7 +457,6 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
|||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// glfw: whenever the mouse moves, this callback is called
|
// glfw: whenever the mouse moves, this callback is called
|
||||||
// -------------------------------------------------------
|
// -------------------------------------------------------
|
||||||
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
||||||
|
|||||||
Reference in New Issue
Block a user