mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-30 20:13:22 +08:00
Code re-work and content update: lighting.
This commit is contained in:
@@ -169,11 +169,11 @@ int main()
|
|||||||
transform = glm::rotate(transform, (float)glfwGetTime(), glm::vec3(0.0f, 0.0f, 1.0f));
|
transform = glm::rotate(transform, (float)glfwGetTime(), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||||
|
|
||||||
// get matrix's uniform location and set matrix
|
// get matrix's uniform location and set matrix
|
||||||
|
ourShader.use();
|
||||||
unsigned int transformLoc = glGetUniformLocation(ourShader.ID, "transform");
|
unsigned int transformLoc = glGetUniformLocation(ourShader.ID, "transform");
|
||||||
glUniformMatrix4fv(transformLoc, 1, GL_FALSE, glm::value_ptr(transform));
|
glUniformMatrix4fv(transformLoc, 1, GL_FALSE, glm::value_ptr(transform));
|
||||||
|
|
||||||
// render container
|
// render container
|
||||||
ourShader.use();
|
|
||||||
glBindVertexArray(VAO);
|
glBindVertexArray(VAO);
|
||||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
||||||
|
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ const unsigned int SCR_HEIGHT = 600;
|
|||||||
|
|
||||||
// camera
|
// camera
|
||||||
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
||||||
float lastX = 800.0f / 2.0;
|
float lastX = SCR_WIDTH / 2.0f;
|
||||||
float lastY = 600.0 / 2.0;
|
float lastY = SCR_HEIGHT / 2.0f;
|
||||||
bool firstMouse = true;
|
bool firstMouse = true;
|
||||||
|
|
||||||
// timing
|
// timing
|
||||||
@@ -281,7 +281,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)
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#version 330 core
|
#version 330 core
|
||||||
out vec4 fragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
uniform vec3 objectColor;
|
uniform vec3 objectColor;
|
||||||
uniform vec3 lightColor;
|
uniform vec3 lightColor;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
fragColor = vec4(lightColor * objectColor, 1.0f);
|
FragColor = vec4(lightColor * objectColor, 1.0);
|
||||||
}
|
}
|
||||||
@@ -7,5 +7,5 @@ uniform mat4 projection;
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = projection * view * model * vec4(aPos, 1.0f);
|
gl_Position = projection * view * model * vec4(aPos, 1.0);
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#version 330 core
|
#version 330 core
|
||||||
out vec4 fragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
fragColor = vec4(1.0f); // set alle 4 vector values to 1.0f
|
FragColor = vec4(1.0); // set alle 4 vector values to 1.0
|
||||||
}
|
}
|
||||||
@@ -7,5 +7,5 @@ uniform mat4 projection;
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = projection * view * model * vec4(aPos, 1.0f);
|
gl_Position = projection * view * model * vec4(aPos, 1.0);
|
||||||
}
|
}
|
||||||
@@ -16,13 +16,18 @@ void mouse_callback(GLFWwindow* window, double xpos, double ypos);
|
|||||||
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 800;
|
||||||
|
const unsigned int SCR_HEIGHT = 600;
|
||||||
|
|
||||||
// camera
|
// camera
|
||||||
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
||||||
float lastX = 800.0f / 2.0;
|
float lastX = SCR_WIDTH / 2.0f;
|
||||||
float lastY = 600.0 / 2.0;
|
float lastY = SCR_HEIGHT / 2.0f;
|
||||||
bool firstMouse = true;
|
bool firstMouse = true;
|
||||||
|
|
||||||
float deltaTime = 0.0f; // time between current frame and last frame
|
// timing
|
||||||
|
float deltaTime = 0.0f;
|
||||||
float lastFrame = 0.0f;
|
float lastFrame = 0.0f;
|
||||||
|
|
||||||
// lighting
|
// lighting
|
||||||
@@ -40,14 +45,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "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);
|
||||||
@@ -159,7 +164,7 @@ int main()
|
|||||||
|
|
||||||
// render
|
// render
|
||||||
// ------
|
// ------
|
||||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// be sure to activate shader when setting uniforms/drawing objects
|
// be sure to activate shader when setting uniforms/drawing objects
|
||||||
@@ -168,7 +173,7 @@ int main()
|
|||||||
lightingShader.setVec3("lightColor", 1.0f, 1.0f, 1.0f);
|
lightingShader.setVec3("lightColor", 1.0f, 1.0f, 1.0f);
|
||||||
|
|
||||||
// view/projection transformations
|
// view/projection transformations
|
||||||
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), 800.0f / 600.0f, 0.1f, 100.0f);
|
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
|
||||||
glm::mat4 view = camera.GetViewMatrix();
|
glm::mat4 view = camera.GetViewMatrix();
|
||||||
lightingShader.setMat4("projection", projection);
|
lightingShader.setMat4("projection", projection);
|
||||||
lightingShader.setMat4("view", view);
|
lightingShader.setMat4("view", view);
|
||||||
@@ -220,7 +225,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)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#version 330 core
|
#version 330 core
|
||||||
out vec4 fragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
in vec3 Normal;
|
in vec3 Normal;
|
||||||
in vec3 FragPos;
|
in vec3 FragPos;
|
||||||
@@ -11,15 +11,15 @@ uniform vec3 objectColor;
|
|||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
// ambient
|
// ambient
|
||||||
float ambientStrength = 0.1f;
|
float ambientStrength = 0.1;
|
||||||
vec3 ambient = ambientStrength * lightColor;
|
vec3 ambient = ambientStrength * lightColor;
|
||||||
|
|
||||||
// diffuse
|
// diffuse
|
||||||
vec3 norm = normalize(Normal);
|
vec3 norm = normalize(Normal);
|
||||||
vec3 lightDir = normalize(lightPos - FragPos);
|
vec3 lightDir = normalize(lightPos - FragPos);
|
||||||
float diff = max(dot(norm, lightDir), 0.0f);
|
float diff = max(dot(norm, lightDir), 0.0);
|
||||||
vec3 diffuse = diff * lightColor;
|
vec3 diffuse = diff * lightColor;
|
||||||
|
|
||||||
vec3 result = (ambient + diffuse) * objectColor;
|
vec3 result = (ambient + diffuse) * objectColor;
|
||||||
fragColor = vec4(result, 1.0f);
|
FragColor = vec4(result, 1.0);
|
||||||
}
|
}
|
||||||
@@ -11,8 +11,8 @@ uniform mat4 projection;
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
FragPos = vec3(model * vec4(aPos, 1.0f));
|
FragPos = vec3(model * vec4(aPos, 1.0));
|
||||||
Normal = aNormal;
|
Normal = aNormal;
|
||||||
|
|
||||||
gl_Position = projection * view * vec4(FragPos, 1.0f);
|
gl_Position = projection * view * vec4(FragPos, 1.0);
|
||||||
}
|
}
|
||||||
7
src/2.lighting/2.1.basic_lighting_diffuse/2.1.lamp.fs
Normal file
7
src/2.lighting/2.1.basic_lighting_diffuse/2.1.lamp.fs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#version 330 core
|
||||||
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
FragColor = vec4(1.0); // set alle 4 vector values to 1.0
|
||||||
|
}
|
||||||
11
src/2.lighting/2.1.basic_lighting_diffuse/2.1.lamp.vs
Normal file
11
src/2.lighting/2.1.basic_lighting_diffuse/2.1.lamp.vs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#version 330 core
|
||||||
|
layout (location = 0) in vec3 aPos;
|
||||||
|
|
||||||
|
uniform mat4 model;
|
||||||
|
uniform mat4 view;
|
||||||
|
uniform mat4 projection;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = projection * view * model * vec4(aPos, 1.0);
|
||||||
|
}
|
||||||
@@ -16,13 +16,18 @@ void mouse_callback(GLFWwindow* window, double xpos, double ypos);
|
|||||||
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 800;
|
||||||
|
const unsigned int SCR_HEIGHT = 600;
|
||||||
|
|
||||||
// camera
|
// camera
|
||||||
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
||||||
float lastX = 800.0f / 2.0;
|
float lastX = SCR_WIDTH / 2.0f;
|
||||||
float lastY = 600.0 / 2.0;
|
float lastY = SCR_HEIGHT / 2.0f;
|
||||||
bool firstMouse = true;
|
bool firstMouse = true;
|
||||||
|
|
||||||
float deltaTime = 0.0f; // time between current frame and last frame
|
// timing
|
||||||
|
float deltaTime = 0.0f;
|
||||||
float lastFrame = 0.0f;
|
float lastFrame = 0.0f;
|
||||||
|
|
||||||
// lighting
|
// lighting
|
||||||
@@ -40,14 +45,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "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);
|
||||||
@@ -70,7 +75,7 @@ int main()
|
|||||||
// build and compile our shader zprogram
|
// build and compile our shader zprogram
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
Shader lightingShader("2.1.basic_lighting.vs", "2.1.basic_lighting.fs");
|
Shader lightingShader("2.1.basic_lighting.vs", "2.1.basic_lighting.fs");
|
||||||
Shader lampShader("1.lamp.vs", "1.lamp.fs");
|
Shader lampShader("2.1.lamp.vs", "2.1.lamp.fs");
|
||||||
|
|
||||||
// set up vertex data (and buffer(s)) and configure vertex attributes
|
// set up vertex data (and buffer(s)) and configure vertex attributes
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
@@ -162,7 +167,7 @@ int main()
|
|||||||
|
|
||||||
// render
|
// render
|
||||||
// ------
|
// ------
|
||||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// be sure to activate shader when setting uniforms/drawing objects
|
// be sure to activate shader when setting uniforms/drawing objects
|
||||||
@@ -172,7 +177,7 @@ int main()
|
|||||||
lightingShader.setVec3("lightPos", lightPos);
|
lightingShader.setVec3("lightPos", lightPos);
|
||||||
|
|
||||||
// view/projection transformations
|
// view/projection transformations
|
||||||
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), 800.0f / 600.0f, 0.1f, 100.0f);
|
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
|
||||||
glm::mat4 view = camera.GetViewMatrix();
|
glm::mat4 view = camera.GetViewMatrix();
|
||||||
lightingShader.setMat4("projection", projection);
|
lightingShader.setMat4("projection", projection);
|
||||||
lightingShader.setMat4("view", view);
|
lightingShader.setMat4("view", view);
|
||||||
@@ -224,7 +229,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)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#version 330 core
|
#version 330 core
|
||||||
out vec4 fragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
in vec3 Normal;
|
in vec3 Normal;
|
||||||
in vec3 FragPos;
|
in vec3 FragPos;
|
||||||
@@ -12,22 +12,22 @@ uniform vec3 objectColor;
|
|||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
// ambient
|
// ambient
|
||||||
float ambientStrength = 0.1f;
|
float ambientStrength = 0.1;
|
||||||
vec3 ambient = ambientStrength * lightColor;
|
vec3 ambient = ambientStrength * lightColor;
|
||||||
|
|
||||||
// diffuse
|
// diffuse
|
||||||
vec3 norm = normalize(Normal);
|
vec3 norm = normalize(Normal);
|
||||||
vec3 lightDir = normalize(lightPos - FragPos);
|
vec3 lightDir = normalize(lightPos - FragPos);
|
||||||
float diff = max(dot(norm, lightDir), 0.0f);
|
float diff = max(dot(norm, lightDir), 0.0);
|
||||||
vec3 diffuse = diff * lightColor;
|
vec3 diffuse = diff * lightColor;
|
||||||
|
|
||||||
// specular
|
// specular
|
||||||
float specularStrength = 0.5f;
|
float specularStrength = 0.5;
|
||||||
vec3 viewDir = normalize(viewPos - FragPos);
|
vec3 viewDir = normalize(viewPos - FragPos);
|
||||||
vec3 reflectDir = reflect(-lightDir, norm);
|
vec3 reflectDir = reflect(-lightDir, norm);
|
||||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
|
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
|
||||||
vec3 specular = specularStrength * spec * lightColor;
|
vec3 specular = specularStrength * spec * lightColor;
|
||||||
|
|
||||||
vec3 result = (ambient + diffuse + specular) * objectColor;
|
vec3 result = (ambient + diffuse + specular) * objectColor;
|
||||||
fragColor = vec4(result, 1.0f);
|
FragColor = vec4(result, 1.0);
|
||||||
}
|
}
|
||||||
@@ -11,8 +11,8 @@ uniform mat4 projection;
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
FragPos = vec3(model * vec4(aPos, 1.0f));
|
FragPos = vec3(model * vec4(aPos, 1.0));
|
||||||
Normal = mat3(transpose(inverse(model))) * aNormal;
|
Normal = mat3(transpose(inverse(model))) * aNormal;
|
||||||
|
|
||||||
gl_Position = projection * view * vec4(FragPos, 1.0f);
|
gl_Position = projection * view * vec4(FragPos, 1.0);
|
||||||
}
|
}
|
||||||
7
src/2.lighting/2.2.basic_lighting_specular/2.2.lamp.fs
Normal file
7
src/2.lighting/2.2.basic_lighting_specular/2.2.lamp.fs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#version 330 core
|
||||||
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
FragColor = vec4(1.0); // set alle 4 vector values to 1.0
|
||||||
|
}
|
||||||
11
src/2.lighting/2.2.basic_lighting_specular/2.2.lamp.vs
Normal file
11
src/2.lighting/2.2.basic_lighting_specular/2.2.lamp.vs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#version 330 core
|
||||||
|
layout (location = 0) in vec3 aPos;
|
||||||
|
|
||||||
|
uniform mat4 model;
|
||||||
|
uniform mat4 view;
|
||||||
|
uniform mat4 projection;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = projection * view * model * vec4(aPos, 1.0);
|
||||||
|
}
|
||||||
@@ -16,13 +16,18 @@ void mouse_callback(GLFWwindow* window, double xpos, double ypos);
|
|||||||
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 800;
|
||||||
|
const unsigned int SCR_HEIGHT = 600;
|
||||||
|
|
||||||
// camera
|
// camera
|
||||||
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
||||||
float lastX = 800.0f / 2.0;
|
float lastX = SCR_WIDTH / 2.0f;
|
||||||
float lastY = 600.0 / 2.0;
|
float lastY = SCR_HEIGHT / 2.0f;
|
||||||
bool firstMouse = true;
|
bool firstMouse = true;
|
||||||
|
|
||||||
float deltaTime = 0.0f; // time between current frame and last frame
|
// timing
|
||||||
|
float deltaTime = 0.0f;
|
||||||
float lastFrame = 0.0f;
|
float lastFrame = 0.0f;
|
||||||
|
|
||||||
// lighting
|
// lighting
|
||||||
@@ -40,14 +45,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "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);
|
||||||
@@ -70,7 +75,7 @@ int main()
|
|||||||
// build and compile our shader zprogram
|
// build and compile our shader zprogram
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
Shader lightingShader("2.2.basic_lighting.vs", "2.2.basic_lighting.fs");
|
Shader lightingShader("2.2.basic_lighting.vs", "2.2.basic_lighting.fs");
|
||||||
Shader lampShader("1.lamp.vs", "1.lamp.fs");
|
Shader lampShader("2.2.lamp.vs", "2.2.lamp.fs");
|
||||||
|
|
||||||
// set up vertex data (and buffer(s)) and configure vertex attributes
|
// set up vertex data (and buffer(s)) and configure vertex attributes
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
@@ -162,7 +167,7 @@ int main()
|
|||||||
|
|
||||||
// render
|
// render
|
||||||
// ------
|
// ------
|
||||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// be sure to activate shader when setting uniforms/drawing objects
|
// be sure to activate shader when setting uniforms/drawing objects
|
||||||
@@ -173,7 +178,7 @@ int main()
|
|||||||
lightingShader.setVec3("viewPos", camera.Position);
|
lightingShader.setVec3("viewPos", camera.Position);
|
||||||
|
|
||||||
// view/projection transformations
|
// view/projection transformations
|
||||||
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), 800.0f / 600.0f, 0.1f, 100.0f);
|
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
|
||||||
glm::mat4 view = camera.GetViewMatrix();
|
glm::mat4 view = camera.GetViewMatrix();
|
||||||
lightingShader.setMat4("projection", projection);
|
lightingShader.setMat4("projection", projection);
|
||||||
lightingShader.setMat4("view", view);
|
lightingShader.setMat4("view", view);
|
||||||
@@ -225,7 +230,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)
|
||||||
|
|||||||
7
src/2.lighting/3.1.materials/3.1.lamp.fs
Normal file
7
src/2.lighting/3.1.materials/3.1.lamp.fs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#version 330 core
|
||||||
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
FragColor = vec4(1.0); // set alle 4 vector values to 1.0
|
||||||
|
}
|
||||||
11
src/2.lighting/3.1.materials/3.1.lamp.vs
Normal file
11
src/2.lighting/3.1.materials/3.1.lamp.vs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#version 330 core
|
||||||
|
layout (location = 0) in vec3 aPos;
|
||||||
|
|
||||||
|
uniform mat4 model;
|
||||||
|
uniform mat4 view;
|
||||||
|
uniform mat4 projection;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = projection * view * model * vec4(aPos, 1.0);
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#version 330 core
|
#version 330 core
|
||||||
out vec4 fragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
struct Material {
|
struct Material {
|
||||||
vec3 ambient;
|
vec3 ambient;
|
||||||
@@ -41,5 +41,5 @@ void main()
|
|||||||
vec3 specular = light.specular * (spec * material.specular);
|
vec3 specular = light.specular * (spec * material.specular);
|
||||||
|
|
||||||
vec3 result = ambient + diffuse + specular;
|
vec3 result = ambient + diffuse + specular;
|
||||||
fragColor = vec4(result, 1.0f);
|
FragColor = vec4(result, 1.0);
|
||||||
}
|
}
|
||||||
@@ -11,8 +11,8 @@ uniform mat4 projection;
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
FragPos = vec3(model * vec4(aPos, 1.0f));
|
FragPos = vec3(model * vec4(aPos, 1.0));
|
||||||
Normal = mat3(transpose(inverse(model))) * aNormal;
|
Normal = mat3(transpose(inverse(model))) * aNormal;
|
||||||
|
|
||||||
gl_Position = projection * view * vec4(FragPos, 1.0f);
|
gl_Position = projection * view * vec4(FragPos, 1.0);
|
||||||
}
|
}
|
||||||
@@ -16,13 +16,18 @@ void mouse_callback(GLFWwindow* window, double xpos, double ypos);
|
|||||||
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 800;
|
||||||
|
const unsigned int SCR_HEIGHT = 600;
|
||||||
|
|
||||||
// camera
|
// camera
|
||||||
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
||||||
float lastX = 800.0f / 2.0;
|
float lastX = SCR_WIDTH / 2.0f;
|
||||||
float lastY = 600.0 / 2.0;
|
float lastY = SCR_HEIGHT / 2.0f;
|
||||||
bool firstMouse = true;
|
bool firstMouse = true;
|
||||||
|
|
||||||
float deltaTime = 0.0f; // time between current frame and last frame
|
// timing
|
||||||
|
float deltaTime = 0.0f;
|
||||||
float lastFrame = 0.0f;
|
float lastFrame = 0.0f;
|
||||||
|
|
||||||
// lighting
|
// lighting
|
||||||
@@ -40,14 +45,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "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);
|
||||||
@@ -70,7 +75,7 @@ int main()
|
|||||||
// build and compile our shader zprogram
|
// build and compile our shader zprogram
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
Shader lightingShader("3.1.materials.vs", "3.1.materials.fs");
|
Shader lightingShader("3.1.materials.vs", "3.1.materials.fs");
|
||||||
Shader lampShader("1.lamp.vs", "1.lamp.fs");
|
Shader lampShader("3.1.lamp.vs", "3.1.lamp.fs");
|
||||||
|
|
||||||
// set up vertex data (and buffer(s)) and configure vertex attributes
|
// set up vertex data (and buffer(s)) and configure vertex attributes
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
@@ -162,7 +167,7 @@ int main()
|
|||||||
|
|
||||||
// render
|
// render
|
||||||
// ------
|
// ------
|
||||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// be sure to activate shader when setting uniforms/drawing objects
|
// be sure to activate shader when setting uniforms/drawing objects
|
||||||
@@ -188,7 +193,7 @@ int main()
|
|||||||
lightingShader.setFloat("material.shininess", 32.0f);
|
lightingShader.setFloat("material.shininess", 32.0f);
|
||||||
|
|
||||||
// view/projection transformations
|
// view/projection transformations
|
||||||
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), 800.0f / 600.0f, 0.1f, 100.0f);
|
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
|
||||||
glm::mat4 view = camera.GetViewMatrix();
|
glm::mat4 view = camera.GetViewMatrix();
|
||||||
lightingShader.setMat4("projection", projection);
|
lightingShader.setMat4("projection", projection);
|
||||||
lightingShader.setMat4("view", view);
|
lightingShader.setMat4("view", view);
|
||||||
@@ -240,7 +245,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)
|
||||||
|
|||||||
7
src/2.lighting/3.2.materials_exercise1/3.2.lamp.fs
Normal file
7
src/2.lighting/3.2.materials_exercise1/3.2.lamp.fs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#version 330 core
|
||||||
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
FragColor = vec4(1.0); // set alle 4 vector values to 1.0
|
||||||
|
}
|
||||||
11
src/2.lighting/3.2.materials_exercise1/3.2.lamp.vs
Normal file
11
src/2.lighting/3.2.materials_exercise1/3.2.lamp.vs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#version 330 core
|
||||||
|
layout (location = 0) in vec3 aPos;
|
||||||
|
|
||||||
|
uniform mat4 model;
|
||||||
|
uniform mat4 view;
|
||||||
|
uniform mat4 projection;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = projection * view * model * vec4(aPos, 1.0);
|
||||||
|
}
|
||||||
45
src/2.lighting/3.2.materials_exercise1/3.2.materials.fs
Normal file
45
src/2.lighting/3.2.materials_exercise1/3.2.materials.fs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#version 330 core
|
||||||
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
struct Material {
|
||||||
|
vec3 ambient;
|
||||||
|
vec3 diffuse;
|
||||||
|
vec3 specular;
|
||||||
|
float shininess;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Light {
|
||||||
|
vec3 position;
|
||||||
|
|
||||||
|
vec3 ambient;
|
||||||
|
vec3 diffuse;
|
||||||
|
vec3 specular;
|
||||||
|
};
|
||||||
|
|
||||||
|
in vec3 FragPos;
|
||||||
|
in vec3 Normal;
|
||||||
|
|
||||||
|
uniform vec3 viewPos;
|
||||||
|
uniform Material material;
|
||||||
|
uniform Light light;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
// ambient
|
||||||
|
vec3 ambient = light.ambient * material.ambient;
|
||||||
|
|
||||||
|
// diffuse
|
||||||
|
vec3 norm = normalize(Normal);
|
||||||
|
vec3 lightDir = normalize(light.position - FragPos);
|
||||||
|
float diff = max(dot(norm, lightDir), 0.0);
|
||||||
|
vec3 diffuse = light.diffuse * (diff * material.diffuse);
|
||||||
|
|
||||||
|
// specular
|
||||||
|
vec3 viewDir = normalize(viewPos - FragPos);
|
||||||
|
vec3 reflectDir = reflect(-lightDir, norm);
|
||||||
|
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
|
||||||
|
vec3 specular = light.specular * (spec * material.specular);
|
||||||
|
|
||||||
|
vec3 result = ambient + diffuse + specular;
|
||||||
|
FragColor = vec4(result, 1.0);
|
||||||
|
}
|
||||||
18
src/2.lighting/3.2.materials_exercise1/3.2.materials.vs
Normal file
18
src/2.lighting/3.2.materials_exercise1/3.2.materials.vs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#version 330 core
|
||||||
|
layout (location = 0) in vec3 aPos;
|
||||||
|
layout (location = 1) in vec3 aNormal;
|
||||||
|
|
||||||
|
out vec3 FragPos;
|
||||||
|
out vec3 Normal;
|
||||||
|
|
||||||
|
uniform mat4 model;
|
||||||
|
uniform mat4 view;
|
||||||
|
uniform mat4 projection;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
FragPos = vec3(model * vec4(aPos, 1.0));
|
||||||
|
Normal = mat3(transpose(inverse(model))) * aNormal;
|
||||||
|
|
||||||
|
gl_Position = projection * view * vec4(FragPos, 1.0);
|
||||||
|
}
|
||||||
@@ -16,13 +16,18 @@ void mouse_callback(GLFWwindow* window, double xpos, double ypos);
|
|||||||
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 800;
|
||||||
|
const unsigned int SCR_HEIGHT = 600;
|
||||||
|
|
||||||
// camera
|
// camera
|
||||||
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
||||||
float lastX = 800.0f / 2.0;
|
float lastX = SCR_WIDTH / 2.0f;
|
||||||
float lastY = 600.0 / 2.0;
|
float lastY = SCR_HEIGHT / 2.0f;
|
||||||
bool firstMouse = true;
|
bool firstMouse = true;
|
||||||
|
|
||||||
float deltaTime = 0.0f; // time between current frame and last frame
|
// timing
|
||||||
|
float deltaTime = 0.0f;
|
||||||
float lastFrame = 0.0f;
|
float lastFrame = 0.0f;
|
||||||
|
|
||||||
// lighting
|
// lighting
|
||||||
@@ -40,14 +45,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "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);
|
||||||
@@ -70,22 +75,22 @@ int main()
|
|||||||
// build and compile our shader zprogram
|
// build and compile our shader zprogram
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
Shader lightingShader("3.1.materials.vs", "3.1.materials.fs");
|
Shader lightingShader("3.1.materials.vs", "3.1.materials.fs");
|
||||||
Shader lampShader("1.lamp.vs", "1.lamp.fs");
|
Shader lampShader("3.1.lamp.vs", "3.1.lamp.fs");
|
||||||
|
|
||||||
// set up vertex data (and buffer(s)) and configure vertex attributes
|
// set up vertex data (and buffer(s)) and configure vertex attributes
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
float vertices[] = {
|
float vertices[] = {
|
||||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||||
0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||||
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||||
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||||
-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||||
|
|
||||||
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||||
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||||
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||||
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||||
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||||
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||||
|
|
||||||
@@ -96,24 +101,24 @@ int main()
|
|||||||
-0.5f, -0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
|
-0.5f, -0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
|
||||||
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
|
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
|
||||||
|
|
||||||
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
|
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
|
||||||
0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
|
0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
|
||||||
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
|
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
|
||||||
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
|
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
|
||||||
0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
|
0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
|
||||||
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
|
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
|
||||||
|
|
||||||
-0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
|
-0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
|
||||||
0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
|
0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
|
||||||
0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
|
0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
|
||||||
0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
|
0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
|
||||||
-0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
|
-0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
|
||||||
-0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
|
-0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
|
||||||
|
|
||||||
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
|
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
|
||||||
0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
|
0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
|
||||||
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
|
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
|
||||||
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
|
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
|
||||||
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
|
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
|
||||||
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f
|
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f
|
||||||
};
|
};
|
||||||
@@ -162,7 +167,7 @@ int main()
|
|||||||
|
|
||||||
// render
|
// render
|
||||||
// ------
|
// ------
|
||||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// be sure to activate shader when setting uniforms/drawing objects
|
// be sure to activate shader when setting uniforms/drawing objects
|
||||||
@@ -182,7 +187,7 @@ int main()
|
|||||||
lightingShader.setFloat("material.shininess", 32.0f);
|
lightingShader.setFloat("material.shininess", 32.0f);
|
||||||
|
|
||||||
// view/projection transformations
|
// view/projection transformations
|
||||||
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), 800.0f / 600.0f, 0.1f, 100.0f);
|
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
|
||||||
glm::mat4 view = camera.GetViewMatrix();
|
glm::mat4 view = camera.GetViewMatrix();
|
||||||
lightingShader.setMat4("projection", projection);
|
lightingShader.setMat4("projection", projection);
|
||||||
lightingShader.setMat4("view", view);
|
lightingShader.setMat4("view", view);
|
||||||
@@ -234,7 +239,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)
|
||||||
|
|||||||
@@ -18,13 +18,18 @@ void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
|||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
unsigned int loadTexture(const char *path);
|
unsigned int loadTexture(const char *path);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 800;
|
||||||
|
const unsigned int SCR_HEIGHT = 600;
|
||||||
|
|
||||||
// camera
|
// camera
|
||||||
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
||||||
float lastX = 800.0f / 2.0;
|
float lastX = SCR_WIDTH / 2.0f;
|
||||||
float lastY = 600.0 / 2.0;
|
float lastY = SCR_HEIGHT / 2.0f;
|
||||||
bool firstMouse = true;
|
bool firstMouse = true;
|
||||||
|
|
||||||
float deltaTime = 0.0f; // time between current frame and last frame
|
// timing
|
||||||
|
float deltaTime = 0.0f;
|
||||||
float lastFrame = 0.0f;
|
float lastFrame = 0.0f;
|
||||||
|
|
||||||
// lighting
|
// lighting
|
||||||
@@ -42,14 +47,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "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);
|
||||||
@@ -72,7 +77,7 @@ int main()
|
|||||||
// build and compile our shader zprogram
|
// build and compile our shader zprogram
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
Shader lightingShader("4.1.lighting_maps.vs", "4.1.lighting_maps.fs");
|
Shader lightingShader("4.1.lighting_maps.vs", "4.1.lighting_maps.fs");
|
||||||
Shader lampShader("1.lamp.vs", "1.lamp.fs");
|
Shader lampShader("4.1.lamp.vs", "4.1.lamp.fs");
|
||||||
|
|
||||||
// set up vertex data (and buffer(s)) and configure vertex attributes
|
// set up vertex data (and buffer(s)) and configure vertex attributes
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
@@ -172,7 +177,7 @@ int main()
|
|||||||
|
|
||||||
// render
|
// render
|
||||||
// ------
|
// ------
|
||||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// be sure to activate shader when setting uniforms/drawing objects
|
// be sure to activate shader when setting uniforms/drawing objects
|
||||||
@@ -190,7 +195,7 @@ int main()
|
|||||||
lightingShader.setFloat("material.shininess", 64.0f);
|
lightingShader.setFloat("material.shininess", 64.0f);
|
||||||
|
|
||||||
// view/projection transformations
|
// view/projection transformations
|
||||||
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), 800.0f / 600.0f, 0.1f, 100.0f);
|
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
|
||||||
glm::mat4 view = camera.GetViewMatrix();
|
glm::mat4 view = camera.GetViewMatrix();
|
||||||
lightingShader.setMat4("projection", projection);
|
lightingShader.setMat4("projection", projection);
|
||||||
lightingShader.setMat4("view", view);
|
lightingShader.setMat4("view", view);
|
||||||
@@ -246,7 +251,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)
|
||||||
|
|||||||
@@ -18,13 +18,18 @@ void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
|||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
unsigned int loadTexture(const char *path);
|
unsigned int loadTexture(const char *path);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 800;
|
||||||
|
const unsigned int SCR_HEIGHT = 600;
|
||||||
|
|
||||||
// camera
|
// camera
|
||||||
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
||||||
float lastX = 800.0f / 2.0;
|
float lastX = SCR_WIDTH / 2.0f;
|
||||||
float lastY = 600.0 / 2.0;
|
float lastY = SCR_HEIGHT / 2.0f;
|
||||||
bool firstMouse = true;
|
bool firstMouse = true;
|
||||||
|
|
||||||
float deltaTime = 0.0f; // time between current frame and last frame
|
// timing
|
||||||
|
float deltaTime = 0.0f;
|
||||||
float lastFrame = 0.0f;
|
float lastFrame = 0.0f;
|
||||||
|
|
||||||
// lighting
|
// lighting
|
||||||
@@ -42,14 +47,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "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);
|
||||||
@@ -72,7 +77,7 @@ int main()
|
|||||||
// build and compile our shader zprogram
|
// build and compile our shader zprogram
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
Shader lightingShader("4.2.lighting_maps.vs", "4.2.lighting_maps.fs");
|
Shader lightingShader("4.2.lighting_maps.vs", "4.2.lighting_maps.fs");
|
||||||
Shader lampShader("1.lamp.vs", "1.lamp.fs");
|
Shader lampShader("4.2.lamp.vs", "4.2.lamp.fs");
|
||||||
|
|
||||||
// set up vertex data (and buffer(s)) and configure vertex attributes
|
// set up vertex data (and buffer(s)) and configure vertex attributes
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
@@ -174,7 +179,7 @@ int main()
|
|||||||
|
|
||||||
// render
|
// render
|
||||||
// ------
|
// ------
|
||||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// be sure to activate shader when setting uniforms/drawing objects
|
// be sure to activate shader when setting uniforms/drawing objects
|
||||||
@@ -191,7 +196,7 @@ int main()
|
|||||||
lightingShader.setFloat("material.shininess", 64.0f);
|
lightingShader.setFloat("material.shininess", 64.0f);
|
||||||
|
|
||||||
// view/projection transformations
|
// view/projection transformations
|
||||||
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), 800.0f / 600.0f, 0.1f, 100.0f);
|
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
|
||||||
glm::mat4 view = camera.GetViewMatrix();
|
glm::mat4 view = camera.GetViewMatrix();
|
||||||
lightingShader.setMat4("projection", projection);
|
lightingShader.setMat4("projection", projection);
|
||||||
lightingShader.setMat4("view", view);
|
lightingShader.setMat4("view", view);
|
||||||
@@ -250,7 +255,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)
|
||||||
@@ -270,7 +274,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)
|
||||||
|
|||||||
@@ -18,13 +18,18 @@ void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
|||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
unsigned int loadTexture(const char *path);
|
unsigned int loadTexture(const char *path);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 800;
|
||||||
|
const unsigned int SCR_HEIGHT = 600;
|
||||||
|
|
||||||
// camera
|
// camera
|
||||||
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
||||||
float lastX = 800.0f / 2.0;
|
float lastX = SCR_WIDTH / 2.0f;
|
||||||
float lastY = 600.0 / 2.0;
|
float lastY = SCR_HEIGHT / 2.0f;
|
||||||
bool firstMouse = true;
|
bool firstMouse = true;
|
||||||
|
|
||||||
float deltaTime = 0.0f; // time between current frame and last frame
|
// timing
|
||||||
|
float deltaTime = 0.0f;
|
||||||
float lastFrame = 0.0f;
|
float lastFrame = 0.0f;
|
||||||
|
|
||||||
// lighting
|
// lighting
|
||||||
@@ -42,14 +47,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "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);
|
||||||
@@ -72,7 +77,7 @@ int main()
|
|||||||
// build and compile our shader zprogram
|
// build and compile our shader zprogram
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
Shader lightingShader("4.3.lighting_maps.vs", "4.3.lighting_maps.fs");
|
Shader lightingShader("4.3.lighting_maps.vs", "4.3.lighting_maps.fs");
|
||||||
Shader lampShader("1.lamp.vs", "1.lamp.fs");
|
Shader lampShader("4.3.lamp.vs", "4.3.lamp.fs");
|
||||||
|
|
||||||
// set up vertex data (and buffer(s)) and configure vertex attributes
|
// set up vertex data (and buffer(s)) and configure vertex attributes
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
@@ -176,7 +181,7 @@ int main()
|
|||||||
|
|
||||||
// render
|
// render
|
||||||
// ------
|
// ------
|
||||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// be sure to activate shader when setting uniforms/drawing objects
|
// be sure to activate shader when setting uniforms/drawing objects
|
||||||
@@ -193,7 +198,7 @@ int main()
|
|||||||
lightingShader.setFloat("material.shininess", 64.0f);
|
lightingShader.setFloat("material.shininess", 64.0f);
|
||||||
|
|
||||||
// view/projection transformations
|
// view/projection transformations
|
||||||
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), 800.0f / 600.0f, 0.1f, 100.0f);
|
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
|
||||||
glm::mat4 view = camera.GetViewMatrix();
|
glm::mat4 view = camera.GetViewMatrix();
|
||||||
lightingShader.setMat4("projection", projection);
|
lightingShader.setMat4("projection", projection);
|
||||||
lightingShader.setMat4("view", view);
|
lightingShader.setMat4("view", view);
|
||||||
@@ -255,7 +260,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)
|
||||||
|
|||||||
@@ -18,13 +18,18 @@ void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
|||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
unsigned int loadTexture(const char *path);
|
unsigned int loadTexture(const char *path);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 800;
|
||||||
|
const unsigned int SCR_HEIGHT = 600;
|
||||||
|
|
||||||
// camera
|
// camera
|
||||||
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
||||||
float lastX = 800.0f / 2.0;
|
float lastX = SCR_WIDTH / 2.0f;
|
||||||
float lastY = 600.0 / 2.0;
|
float lastY = SCR_HEIGHT / 2.0f;
|
||||||
bool firstMouse = true;
|
bool firstMouse = true;
|
||||||
|
|
||||||
float deltaTime = 0.0f; // time between current frame and last frame
|
// timing
|
||||||
|
float deltaTime = 0.0f;
|
||||||
float lastFrame = 0.0f;
|
float lastFrame = 0.0f;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
@@ -38,14 +43,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "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);
|
||||||
@@ -68,7 +73,7 @@ int main()
|
|||||||
// build and compile shaders
|
// build and compile shaders
|
||||||
// -------------------------
|
// -------------------------
|
||||||
Shader lightingShader("5.1.light_casters.vs", "5.1.light_casters.fs");
|
Shader lightingShader("5.1.light_casters.vs", "5.1.light_casters.fs");
|
||||||
Shader lampShader("1.lamp.vs", "1.lamp.fs");
|
Shader lampShader("5.1.lamp.vs", "5.1.lamp.fs");
|
||||||
|
|
||||||
// set up vertex data (and buffer(s)) and configure vertex attributes
|
// set up vertex data (and buffer(s)) and configure vertex attributes
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
@@ -183,7 +188,7 @@ int main()
|
|||||||
|
|
||||||
// render
|
// render
|
||||||
// ------
|
// ------
|
||||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// be sure to activate shader when setting uniforms/drawing objects
|
// be sure to activate shader when setting uniforms/drawing objects
|
||||||
@@ -200,7 +205,7 @@ int main()
|
|||||||
lightingShader.setFloat("material.shininess", 32.0f);
|
lightingShader.setFloat("material.shininess", 32.0f);
|
||||||
|
|
||||||
// view/projection transformations
|
// view/projection transformations
|
||||||
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), 800.0f / 600.0f, 0.1f, 100.0f);
|
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
|
||||||
glm::mat4 view = camera.GetViewMatrix();
|
glm::mat4 view = camera.GetViewMatrix();
|
||||||
lightingShader.setMat4("projection", projection);
|
lightingShader.setMat4("projection", projection);
|
||||||
lightingShader.setMat4("view", view);
|
lightingShader.setMat4("view", view);
|
||||||
@@ -273,7 +278,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)
|
||||||
|
|||||||
@@ -18,13 +18,18 @@ void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
|||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
unsigned int loadTexture(const char *path);
|
unsigned int loadTexture(const char *path);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 800;
|
||||||
|
const unsigned int SCR_HEIGHT = 600;
|
||||||
|
|
||||||
// camera
|
// camera
|
||||||
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
||||||
float lastX = 800.0f / 2.0;
|
float lastX = SCR_WIDTH / 2.0f;
|
||||||
float lastY = 600.0 / 2.0;
|
float lastY = SCR_HEIGHT / 2.0f;
|
||||||
bool firstMouse = true;
|
bool firstMouse = true;
|
||||||
|
|
||||||
float deltaTime = 0.0f; // time between current frame and last frame
|
// timing
|
||||||
|
float deltaTime = 0.0f;
|
||||||
float lastFrame = 0.0f;
|
float lastFrame = 0.0f;
|
||||||
|
|
||||||
// lighting
|
// lighting
|
||||||
@@ -41,14 +46,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "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);
|
||||||
@@ -71,7 +76,7 @@ int main()
|
|||||||
// build and compile our shader zprogram
|
// build and compile our shader zprogram
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
Shader lightingShader("5.2.light_casters.vs", "5.2.light_casters.fs");
|
Shader lightingShader("5.2.light_casters.vs", "5.2.light_casters.fs");
|
||||||
Shader lampShader("1.lamp.vs", "1.lamp.fs");
|
Shader lampShader("5.2.lamp.vs", "5.2.lamp.fs");
|
||||||
|
|
||||||
// set up vertex data (and buffer(s)) and configure vertex attributes
|
// set up vertex data (and buffer(s)) and configure vertex attributes
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
@@ -186,7 +191,7 @@ int main()
|
|||||||
|
|
||||||
// render
|
// render
|
||||||
// ------
|
// ------
|
||||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// be sure to activate shader when setting uniforms/drawing objects
|
// be sure to activate shader when setting uniforms/drawing objects
|
||||||
@@ -206,7 +211,7 @@ int main()
|
|||||||
lightingShader.setFloat("material.shininess", 32.0f);
|
lightingShader.setFloat("material.shininess", 32.0f);
|
||||||
|
|
||||||
// view/projection transformations
|
// view/projection transformations
|
||||||
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), 800.0f / 600.0f, 0.1f, 100.0f);
|
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
|
||||||
glm::mat4 view = camera.GetViewMatrix();
|
glm::mat4 view = camera.GetViewMatrix();
|
||||||
lightingShader.setMat4("projection", projection);
|
lightingShader.setMat4("projection", projection);
|
||||||
lightingShader.setMat4("view", view);
|
lightingShader.setMat4("view", view);
|
||||||
@@ -275,7 +280,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)
|
||||||
@@ -295,7 +299,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)
|
||||||
|
|||||||
@@ -18,13 +18,18 @@ void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
|||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
unsigned int loadTexture(const char *path);
|
unsigned int loadTexture(const char *path);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 800;
|
||||||
|
const unsigned int SCR_HEIGHT = 600;
|
||||||
|
|
||||||
// camera
|
// camera
|
||||||
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
||||||
float lastX = 800.0f / 2.0;
|
float lastX = SCR_WIDTH / 2.0f;
|
||||||
float lastY = 600.0 / 2.0;
|
float lastY = SCR_HEIGHT / 2.0f;
|
||||||
bool firstMouse = true;
|
bool firstMouse = true;
|
||||||
|
|
||||||
float deltaTime = 0.0f; // time between current frame and last frame
|
// timing
|
||||||
|
float deltaTime = 0.0f;
|
||||||
float lastFrame = 0.0f;
|
float lastFrame = 0.0f;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
@@ -38,14 +43,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "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);
|
||||||
@@ -68,7 +73,7 @@ int main()
|
|||||||
// build and compile our shader zprogram
|
// build and compile our shader zprogram
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
Shader lightingShader("5.3.light_casters.vs", "5.3.light_casters.fs");
|
Shader lightingShader("5.3.light_casters.vs", "5.3.light_casters.fs");
|
||||||
Shader lampShader("1.lamp.vs", "1.lamp.fs");
|
Shader lampShader("5.3.lamp.vs", "5.3.lamp.fs");
|
||||||
|
|
||||||
// set up vertex data (and buffer(s)) and configure vertex attributes
|
// set up vertex data (and buffer(s)) and configure vertex attributes
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
@@ -183,7 +188,7 @@ int main()
|
|||||||
|
|
||||||
// render
|
// render
|
||||||
// ------
|
// ------
|
||||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// be sure to activate shader when setting uniforms/drawing objects
|
// be sure to activate shader when setting uniforms/drawing objects
|
||||||
@@ -207,7 +212,7 @@ int main()
|
|||||||
lightingShader.setFloat("material.shininess", 32.0f);
|
lightingShader.setFloat("material.shininess", 32.0f);
|
||||||
|
|
||||||
// view/projection transformations
|
// view/projection transformations
|
||||||
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), 800.0f / 600.0f, 0.1f, 100.0f);
|
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
|
||||||
glm::mat4 view = camera.GetViewMatrix();
|
glm::mat4 view = camera.GetViewMatrix();
|
||||||
lightingShader.setMat4("projection", projection);
|
lightingShader.setMat4("projection", projection);
|
||||||
lightingShader.setMat4("view", view);
|
lightingShader.setMat4("view", view);
|
||||||
@@ -276,7 +281,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)
|
||||||
@@ -296,7 +300,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)
|
||||||
|
|||||||
@@ -18,13 +18,18 @@ void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
|||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
unsigned int loadTexture(const char *path);
|
unsigned int loadTexture(const char *path);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 800;
|
||||||
|
const unsigned int SCR_HEIGHT = 600;
|
||||||
|
|
||||||
// camera
|
// camera
|
||||||
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
||||||
float lastX = 800.0f / 2.0;
|
float lastX = SCR_WIDTH / 2.0f;
|
||||||
float lastY = 600.0 / 2.0;
|
float lastY = SCR_HEIGHT / 2.0f;
|
||||||
bool firstMouse = true;
|
bool firstMouse = true;
|
||||||
|
|
||||||
float deltaTime = 0.0f; // time between current frame and last frame
|
// timing
|
||||||
|
float deltaTime = 0.0f;
|
||||||
float lastFrame = 0.0f;
|
float lastFrame = 0.0f;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
@@ -38,14 +43,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "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);
|
||||||
@@ -68,7 +73,7 @@ int main()
|
|||||||
// build and compile our shader zprogram
|
// build and compile our shader zprogram
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
Shader lightingShader("5.4.light_casters.vs", "5.4.light_casters.fs");
|
Shader lightingShader("5.4.light_casters.vs", "5.4.light_casters.fs");
|
||||||
Shader lampShader("1.lamp.vs", "1.lamp.fs");
|
Shader lampShader("5.4.lamp.vs", "5.4.lamp.fs");
|
||||||
|
|
||||||
// set up vertex data (and buffer(s)) and configure vertex attributes
|
// set up vertex data (and buffer(s)) and configure vertex attributes
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
@@ -183,7 +188,7 @@ int main()
|
|||||||
|
|
||||||
// render
|
// render
|
||||||
// ------
|
// ------
|
||||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// be sure to activate shader when setting uniforms/drawing objects
|
// be sure to activate shader when setting uniforms/drawing objects
|
||||||
@@ -208,7 +213,7 @@ int main()
|
|||||||
lightingShader.setFloat("material.shininess", 32.0f);
|
lightingShader.setFloat("material.shininess", 32.0f);
|
||||||
|
|
||||||
// view/projection transformations
|
// view/projection transformations
|
||||||
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), 800.0f / 600.0f, 0.1f, 100.0f);
|
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
|
||||||
glm::mat4 view = camera.GetViewMatrix();
|
glm::mat4 view = camera.GetViewMatrix();
|
||||||
lightingShader.setMat4("projection", projection);
|
lightingShader.setMat4("projection", projection);
|
||||||
lightingShader.setMat4("view", view);
|
lightingShader.setMat4("view", view);
|
||||||
@@ -238,7 +243,6 @@ int main()
|
|||||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// again, a lamp object is weird when we only have a spot light, don't render the light object
|
// again, a lamp object is weird when we only have a spot light, don't render the light object
|
||||||
// lampShader.use();
|
// lampShader.use();
|
||||||
// lampShader.setMat4("projection", projection);
|
// lampShader.setMat4("projection", projection);
|
||||||
@@ -277,7 +281,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)
|
||||||
@@ -297,7 +300,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)
|
||||||
|
|||||||
@@ -18,13 +18,18 @@ void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
|||||||
void processInput(GLFWwindow *window);
|
void processInput(GLFWwindow *window);
|
||||||
unsigned int loadTexture(const char *path);
|
unsigned int loadTexture(const char *path);
|
||||||
|
|
||||||
|
// settings
|
||||||
|
const unsigned int SCR_WIDTH = 800;
|
||||||
|
const unsigned int SCR_HEIGHT = 600;
|
||||||
|
|
||||||
// camera
|
// camera
|
||||||
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
|
||||||
float lastX = 800.0f / 2.0;
|
float lastX = SCR_WIDTH / 2.0f;
|
||||||
float lastY = 600.0 / 2.0;
|
float lastY = SCR_HEIGHT / 2.0f;
|
||||||
bool firstMouse = true;
|
bool firstMouse = true;
|
||||||
|
|
||||||
float deltaTime = 0.0f; // time between current frame and last frame
|
// timing
|
||||||
|
float deltaTime = 0.0f;
|
||||||
float lastFrame = 0.0f;
|
float lastFrame = 0.0f;
|
||||||
|
|
||||||
// lighting
|
// lighting
|
||||||
@@ -41,14 +46,14 @@ int main()
|
|||||||
|
|
||||||
// glfw window creation
|
// glfw window creation
|
||||||
// --------------------
|
// --------------------
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "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);
|
||||||
@@ -71,7 +76,7 @@ int main()
|
|||||||
// build and compile our shader zprogram
|
// build and compile our shader zprogram
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
Shader lightingShader("6.multiple_lights.vs", "6.multiple_lights.fs");
|
Shader lightingShader("6.multiple_lights.vs", "6.multiple_lights.fs");
|
||||||
Shader lampShader("1.lamp.vs", "1.lamp.fs");
|
Shader lampShader("6.lamp.vs", "6.lamp.fs");
|
||||||
|
|
||||||
// set up vertex data (and buffer(s)) and configure vertex attributes
|
// set up vertex data (and buffer(s)) and configure vertex attributes
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
@@ -193,7 +198,7 @@ int main()
|
|||||||
|
|
||||||
// render
|
// render
|
||||||
// ------
|
// ------
|
||||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// be sure to activate shader when setting uniforms/drawing objects
|
// be sure to activate shader when setting uniforms/drawing objects
|
||||||
@@ -257,7 +262,7 @@ int main()
|
|||||||
lightingShader.setFloat("spotLight.outerCutOff", glm::cos(glm::radians(15.0f)));
|
lightingShader.setFloat("spotLight.outerCutOff", glm::cos(glm::radians(15.0f)));
|
||||||
|
|
||||||
// view/projection transformations
|
// view/projection transformations
|
||||||
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), 800.0f / 600.0f, 0.1f, 100.0f);
|
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
|
||||||
glm::mat4 view = camera.GetViewMatrix();
|
glm::mat4 view = camera.GetViewMatrix();
|
||||||
lightingShader.setMat4("projection", projection);
|
lightingShader.setMat4("projection", projection);
|
||||||
lightingShader.setMat4("view", view);
|
lightingShader.setMat4("view", view);
|
||||||
@@ -287,7 +292,6 @@ int main()
|
|||||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// also draw the lamp object(s)
|
// also draw the lamp object(s)
|
||||||
lampShader.use();
|
lampShader.use();
|
||||||
lampShader.setMat4("projection", projection);
|
lampShader.setMat4("projection", projection);
|
||||||
@@ -330,7 +334,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)
|
||||||
@@ -350,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)
|
||||||
|
|||||||
Reference in New Issue
Block a user