diff --git a/src/1.getting_started/6.1.coordinate_systems/6.1.coordinate_systems.fs b/src/1.getting_started/6.1.coordinate_systems/6.1.coordinate_systems.fs index c7652e0..44839bc 100644 --- a/src/1.getting_started/6.1.coordinate_systems/6.1.coordinate_systems.fs +++ b/src/1.getting_started/6.1.coordinate_systems/6.1.coordinate_systems.fs @@ -1,8 +1,7 @@ #version 330 core -out vec4 fragColor; +out vec4 FragColor; -in vec3 ourColor; -in vec2 texCoord; +in vec2 TexCoord; // texture samplers uniform sampler2D texture1; @@ -11,5 +10,5 @@ uniform sampler2D texture2; void main() { // linearly interpolate between both textures (80% container, 20% awesomeface) - fragColor = mix(texture(texture1, texCoord), texture(texture2, texCoord), 0.2); + FragColor = mix(texture(texture1, TexCoord), texture(texture2, TexCoord), 0.2); } \ No newline at end of file diff --git a/src/1.getting_started/6.1.coordinate_systems/6.1.coordinate_systems.vs b/src/1.getting_started/6.1.coordinate_systems/6.1.coordinate_systems.vs index 10577d9..2c0d89a 100644 --- a/src/1.getting_started/6.1.coordinate_systems/6.1.coordinate_systems.vs +++ b/src/1.getting_started/6.1.coordinate_systems/6.1.coordinate_systems.vs @@ -1,10 +1,8 @@ #version 330 core layout (location = 0) in vec3 aPos; -layout (location = 1) in vec3 aColor; -layout (location = 2) in vec2 aTexCoord; +layout (location = 1) in vec2 aTexCoord; -out vec3 ourColor; -out vec2 texCoord; +out vec2 TexCoord; uniform mat4 model; uniform mat4 view; @@ -12,7 +10,6 @@ uniform mat4 projection; void main() { - gl_Position = projection * view * model * vec4(aPos, 1.0f); - ourColor = aColor; - texCoord = vec2(aTexCoord.x, aTexCoord.y); + gl_Position = projection * view * model * vec4(aPos, 1.0); + TexCoord = vec2(aTexCoord.x, aTexCoord.y); } \ No newline at end of file diff --git a/src/1.getting_started/6.1.coordinate_systems/coordinate_systems.cpp b/src/1.getting_started/6.1.coordinate_systems/coordinate_systems.cpp index 19322f9..90fd2cd 100644 --- a/src/1.getting_started/6.1.coordinate_systems/coordinate_systems.cpp +++ b/src/1.getting_started/6.1.coordinate_systems/coordinate_systems.cpp @@ -14,6 +14,10 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow *window); +// settings +const unsigned int SCR_WIDTH = 800; +const unsigned int SCR_HEIGHT = 600; + int main() { // glfw: initialize and configure @@ -26,14 +30,14 @@ int main() // glfw window creation // -------------------- - GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL); - glfwMakeContextCurrent(window); + GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } + glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); // glad: load all OpenGL function pointers @@ -51,11 +55,11 @@ int main() // set up vertex data (and buffer(s)) and configure vertex attributes // ------------------------------------------------------------------ float vertices[] = { - // positions // colors // texture coords - 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, // top right - 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, // bottom right - -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom left - -0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f // top left + // positions // texture coords + 0.5f, 0.5f, 0.0f, 1.0f, 1.0f, // top right + 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, // bottom right + -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, // bottom left + -0.5f, 0.5f, 0.0f, 0.0f, 1.0f // top left }; unsigned int indices[] = { 0, 1, 3, // first triangle @@ -75,14 +79,11 @@ int main() glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); // position attribute - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0); glEnableVertexAttribArray(0); - // color attribute - glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float))); - glEnableVertexAttribArray(1); // texture coord attribute - glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float))); - glEnableVertexAttribArray(2); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float))); + glEnableVertexAttribArray(1); // load and create a texture @@ -99,9 +100,9 @@ int main() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // load image, create texture and generate mipmaps - int width, height, nrComponents; + int width, height, nrChannels; stbi_set_flip_vertically_on_load(true); // tell stb_image.h to flip loaded texture's on the y-axis. - unsigned char *data = stbi_load(FileSystem::getPath("resources/textures/container.jpg").c_str(), &width, &height, &nrComponents, 0); + unsigned char *data = stbi_load(FileSystem::getPath("resources/textures/container.jpg").c_str(), &width, &height, &nrChannels, 0); if (data) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); @@ -123,7 +124,7 @@ int main() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // load image, create texture and generate mipmaps - data = stbi_load(FileSystem::getPath("resources/textures/awesomeface.png").c_str(), &width, &height, &nrComponents, 0); + data = stbi_load(FileSystem::getPath("resources/textures/awesomeface.png").c_str(), &width, &height, &nrChannels, 0); if (data) { // note that the awesomeface.png has transparency and thus an alpha channel, so make sure to tell OpenGL the data type is of GL_RGBA diff --git a/src/1.getting_started/6.2.coordinate_systems_depth/6.2.coordinate_systems.fs b/src/1.getting_started/6.2.coordinate_systems_depth/6.2.coordinate_systems.fs index 43d8561..44839bc 100644 --- a/src/1.getting_started/6.2.coordinate_systems_depth/6.2.coordinate_systems.fs +++ b/src/1.getting_started/6.2.coordinate_systems_depth/6.2.coordinate_systems.fs @@ -1,7 +1,7 @@ #version 330 core -out vec4 fragColor; +out vec4 FragColor; -in vec2 texCoord; +in vec2 TexCoord; // texture samplers uniform sampler2D texture1; @@ -10,5 +10,5 @@ uniform sampler2D texture2; void main() { // linearly interpolate between both textures (80% container, 20% awesomeface) - fragColor = mix(texture(texture1, texCoord), texture(texture2, texCoord), 0.2); + FragColor = mix(texture(texture1, TexCoord), texture(texture2, TexCoord), 0.2); } \ No newline at end of file diff --git a/src/1.getting_started/6.2.coordinate_systems_depth/6.2.coordinate_systems.vs b/src/1.getting_started/6.2.coordinate_systems_depth/6.2.coordinate_systems.vs index 1e26e0d..e91af6d 100644 --- a/src/1.getting_started/6.2.coordinate_systems_depth/6.2.coordinate_systems.vs +++ b/src/1.getting_started/6.2.coordinate_systems_depth/6.2.coordinate_systems.vs @@ -2,7 +2,7 @@ layout (location = 0) in vec3 aPos; layout (location = 1) in vec2 aTexCoord; -out vec2 texCoord; +out vec2 TexCoord; uniform mat4 model; uniform mat4 view; @@ -11,5 +11,5 @@ uniform mat4 projection; void main() { gl_Position = projection * view * model * vec4(aPos, 1.0f); - texCoord = vec2(aTexCoord.x, aTexCoord.y); + TexCoord = vec2(aTexCoord.x, aTexCoord.y); } \ No newline at end of file diff --git a/src/1.getting_started/6.2.coordinate_systems_depth/coordinate_systems_depth.cpp b/src/1.getting_started/6.2.coordinate_systems_depth/coordinate_systems_depth.cpp index 41457fa..ee2e08e 100644 --- a/src/1.getting_started/6.2.coordinate_systems_depth/coordinate_systems_depth.cpp +++ b/src/1.getting_started/6.2.coordinate_systems_depth/coordinate_systems_depth.cpp @@ -14,6 +14,10 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow *window); +// settings +const unsigned int SCR_WIDTH = 800; +const unsigned int SCR_HEIGHT = 600; + int main() { // glfw: initialize and configure @@ -26,14 +30,14 @@ int main() // glfw window creation // -------------------- - GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL); - glfwMakeContextCurrent(window); + GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } + glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); // glad: load all OpenGL function pointers @@ -128,9 +132,9 @@ int main() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // load image, create texture and generate mipmaps - int width, height, nrComponents; + int width, height, nrChannels; stbi_set_flip_vertically_on_load(true); // tell stb_image.h to flip loaded texture's on the y-axis. - unsigned char *data = stbi_load(FileSystem::getPath("resources/textures/container.jpg").c_str(), &width, &height, &nrComponents, 0); + unsigned char *data = stbi_load(FileSystem::getPath("resources/textures/container.jpg").c_str(), &width, &height, &nrChannels, 0); if (data) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); @@ -152,7 +156,7 @@ int main() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // load image, create texture and generate mipmaps - data = stbi_load(FileSystem::getPath("resources/textures/awesomeface.png").c_str(), &width, &height, &nrComponents, 0); + data = stbi_load(FileSystem::getPath("resources/textures/awesomeface.png").c_str(), &width, &height, &nrChannels, 0); if (data) { // note that the awesomeface.png has transparency and thus an alpha channel, so make sure to tell OpenGL the data type is of GL_RGBA diff --git a/src/1.getting_started/6.3.coordinate_systems_multiple/6.3.coordinate_systems.fs b/src/1.getting_started/6.3.coordinate_systems_multiple/6.3.coordinate_systems.fs index eb67075..be379bd 100644 --- a/src/1.getting_started/6.3.coordinate_systems_multiple/6.3.coordinate_systems.fs +++ b/src/1.getting_started/6.3.coordinate_systems_multiple/6.3.coordinate_systems.fs @@ -1,12 +1,12 @@ #version 330 core -in vec2 TexCoord; +out vec4 FragColor; -out vec4 color; +in vec2 TexCoord; uniform sampler2D ourTexture1; uniform sampler2D ourTexture2; void main() { - color = mix(texture(ourTexture1, TexCoord), texture(ourTexture2, TexCoord), 0.2); + FragColor = mix(texture(ourTexture1, TexCoord), texture(ourTexture2, TexCoord), 0.2); } \ No newline at end of file diff --git a/src/1.getting_started/6.3.coordinate_systems_multiple/6.3.coordinate_systems.vs b/src/1.getting_started/6.3.coordinate_systems_multiple/6.3.coordinate_systems.vs index ae6ca8b..523e2a8 100644 --- a/src/1.getting_started/6.3.coordinate_systems_multiple/6.3.coordinate_systems.vs +++ b/src/1.getting_started/6.3.coordinate_systems_multiple/6.3.coordinate_systems.vs @@ -1,6 +1,6 @@ #version 330 core -layout (location = 0) in vec3 position; -layout (location = 2) in vec2 texCoord; +layout (location = 0) in vec3 aPos; +layout (location = 1) in vec2 aTexCoord; out vec2 TexCoord; @@ -10,6 +10,6 @@ uniform mat4 projection; void main() { - gl_Position = projection * view * model * vec4(position, 1.0f); - TexCoord = vec2(texCoord.x, 1.0 - texCoord.y); + gl_Position = projection * view * model * vec4(aPos, 1.0f); + TexCoord = vec2(aTexCoord.x, 1.0 - aTexCoord.y); } \ No newline at end of file diff --git a/src/1.getting_started/6.3.coordinate_systems_multiple/coordinate_systems_multiple.cpp b/src/1.getting_started/6.3.coordinate_systems_multiple/coordinate_systems_multiple.cpp index 6b88ed2..8ddb8b6 100644 --- a/src/1.getting_started/6.3.coordinate_systems_multiple/coordinate_systems_multiple.cpp +++ b/src/1.getting_started/6.3.coordinate_systems_multiple/coordinate_systems_multiple.cpp @@ -14,6 +14,10 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow *window); +// settings +const unsigned int SCR_WIDTH = 800; +const unsigned int SCR_HEIGHT = 600; + int main() { // glfw: initialize and configure @@ -26,14 +30,14 @@ int main() // glfw window creation // -------------------- - GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL); - glfwMakeContextCurrent(window); + GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } + glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); // glad: load all OpenGL function pointers @@ -141,9 +145,9 @@ int main() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // load image, create texture and generate mipmaps - int width, height, nrComponents; + int width, height, nrChannels; stbi_set_flip_vertically_on_load(true); // tell stb_image.h to flip loaded texture's on the y-axis. - unsigned char *data = stbi_load(FileSystem::getPath("resources/textures/container.jpg").c_str(), &width, &height, &nrComponents, 0); + unsigned char *data = stbi_load(FileSystem::getPath("resources/textures/container.jpg").c_str(), &width, &height, &nrChannels, 0); if (data) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); @@ -165,7 +169,7 @@ int main() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // load image, create texture and generate mipmaps - data = stbi_load(FileSystem::getPath("resources/textures/awesomeface.png").c_str(), &width, &height, &nrComponents, 0); + data = stbi_load(FileSystem::getPath("resources/textures/awesomeface.png").c_str(), &width, &height, &nrChannels, 0); if (data) { // note that the awesomeface.png has transparency and thus an alpha channel, so make sure to tell OpenGL the data type is of GL_RGBA @@ -218,7 +222,7 @@ int main() // render boxes glBindVertexArray(VAO); - for (GLuint i = 0; i < 10; i++) + for (unsigned int i = 0; i < 10; i++) { // calculate the model matrix for each object and pass it to shader before drawing glm::mat4 model;