diff --git a/includes/learnopengl/shader_s.h b/includes/learnopengl/shader_s.h index 93906d3..6c46f05 100644 --- a/includes/learnopengl/shader_s.h +++ b/includes/learnopengl/shader_s.h @@ -32,13 +32,13 @@ public: std::stringstream vShaderStream, fShaderStream; // read file's buffer contents into streams vShaderStream << vShaderFile.rdbuf(); - fShaderStream << fShaderFile.rdbuf(); + fShaderStream << fShaderFile.rdbuf(); // close file handlers vShaderFile.close(); fShaderFile.close(); // convert stream into string - vertexCode = vShaderStream.str(); - fragmentCode = fShaderStream.str(); + vertexCode = vShaderStream.str(); + fragmentCode = fShaderStream.str(); } catch (std::ifstream::failure e) { @@ -96,10 +96,10 @@ public: private: // utility function for checking shader compilation/linking errors. // ------------------------------------------------------------------------ - void checkCompileErrors(GLuint shader, std::string type) + void checkCompileErrors(unsigned int shader, std::string type) { - GLint success; - GLchar infoLog[1024]; + int success; + char infoLog[1024]; if (type != "PROGRAM") { glGetShaderiv(shader, GL_COMPILE_STATUS, &success); diff --git a/src/1.getting_started/1.1.hello_window/hello_window.cpp b/src/1.getting_started/1.1.hello_window/hello_window.cpp index ee6d191..4a5f6f6 100644 --- a/src/1.getting_started/1.1.hello_window/hello_window.cpp +++ b/src/1.getting_started/1.1.hello_window/hello_window.cpp @@ -6,6 +6,10 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow *window); +// settings +const unsigned int SCR_WIDTH = 1280; +const unsigned int SCR_HEIGHT = 720; + int main() { // glfw: initialize and configure @@ -18,14 +22,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 diff --git a/src/1.getting_started/1.2.hello_window_clear/hello_window_clear.cpp b/src/1.getting_started/1.2.hello_window_clear/hello_window_clear.cpp index 30ecaee..dd98fd4 100644 --- a/src/1.getting_started/1.2.hello_window_clear/hello_window_clear.cpp +++ b/src/1.getting_started/1.2.hello_window_clear/hello_window_clear.cpp @@ -6,6 +6,10 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow *window); +// settings +const unsigned int SCR_WIDTH = 1280; +const unsigned int SCR_HEIGHT = 720; + int main() { // glfw: initialize and configure @@ -18,14 +22,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 diff --git a/src/1.getting_started/2.1.hello_triangle/hello_triangle.cpp b/src/1.getting_started/2.1.hello_triangle/hello_triangle.cpp index 8e5b515..ecfb59c 100644 --- a/src/1.getting_started/2.1.hello_triangle/hello_triangle.cpp +++ b/src/1.getting_started/2.1.hello_triangle/hello_triangle.cpp @@ -6,6 +6,10 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow *window); +// settings +const unsigned int SCR_WIDTH = 1280; +const unsigned int SCR_HEIGHT = 720; + const char *vertexShaderSource = "#version 330 core\n" "layout (location = 0) in vec3 aPos;\n" "void main()\n" @@ -13,10 +17,10 @@ const char *vertexShaderSource = "#version 330 core\n" " gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n" "}\0"; const char *fragmentShaderSource = "#version 330 core\n" - "out vec4 fragColor;\n" + "out vec4 FragColor;\n" "void main()\n" "{\n" - " fragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n" + " FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n" "}\n\0"; int main() @@ -31,14 +35,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 diff --git a/src/1.getting_started/2.2.hello_triangle_indexed/hello_triangle_indexed.cpp b/src/1.getting_started/2.2.hello_triangle_indexed/hello_triangle_indexed.cpp index cd2a2a0..47a846f 100644 --- a/src/1.getting_started/2.2.hello_triangle_indexed/hello_triangle_indexed.cpp +++ b/src/1.getting_started/2.2.hello_triangle_indexed/hello_triangle_indexed.cpp @@ -6,6 +6,10 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow *window); +// settings +const unsigned int SCR_WIDTH = 1280; +const unsigned int SCR_HEIGHT = 720; + const char *vertexShaderSource = "#version 330 core\n" "layout (location = 0) in vec3 aPos;\n" "void main()\n" @@ -13,10 +17,10 @@ const char *vertexShaderSource = "#version 330 core\n" " gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n" "}\0"; const char *fragmentShaderSource = "#version 330 core\n" - "out vec4 fragColor;\n" + "out vec4 FragColor;\n" "void main()\n" "{\n" - " fragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n" + " FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n" "}\n\0"; int main() @@ -31,14 +35,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 diff --git a/src/1.getting_started/2.3.hello_triangle_exercise1/hello_triangle_exercise1.cpp b/src/1.getting_started/2.3.hello_triangle_exercise1/hello_triangle_exercise1.cpp index a6eefa7..40ee6e9 100644 --- a/src/1.getting_started/2.3.hello_triangle_exercise1/hello_triangle_exercise1.cpp +++ b/src/1.getting_started/2.3.hello_triangle_exercise1/hello_triangle_exercise1.cpp @@ -6,6 +6,10 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow *window); +// settings +const unsigned int SCR_WIDTH = 1280; +const unsigned int SCR_HEIGHT = 720; + const char *vertexShaderSource = "#version 330 core\n" "layout (location = 0) in vec3 aPos;\n" "void main()\n" @@ -13,10 +17,10 @@ const char *vertexShaderSource = "#version 330 core\n" " gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n" "}\0"; const char *fragmentShaderSource = "#version 330 core\n" - "out vec4 fragColor;\n" + "out vec4 FragColor;\n" "void main()\n" "{\n" - " fragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n" + " FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n" "}\n\0"; int main() @@ -31,14 +35,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 diff --git a/src/1.getting_started/2.4.hello_triangle_exercise2/hello_triangle_exercise2.cpp b/src/1.getting_started/2.4.hello_triangle_exercise2/hello_triangle_exercise2.cpp index 994552e..7d57d7c 100644 --- a/src/1.getting_started/2.4.hello_triangle_exercise2/hello_triangle_exercise2.cpp +++ b/src/1.getting_started/2.4.hello_triangle_exercise2/hello_triangle_exercise2.cpp @@ -6,6 +6,10 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow *window); +// settings +const unsigned int SCR_WIDTH = 1280; +const unsigned int SCR_HEIGHT = 720; + const char *vertexShaderSource = "#version 330 core\n" "layout (location = 0) in vec3 aPos;\n" "void main()\n" @@ -13,10 +17,10 @@ const char *vertexShaderSource = "#version 330 core\n" " gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n" "}\0"; const char *fragmentShaderSource = "#version 330 core\n" - "out vec4 fragColor;\n" + "out vec4 FragColor;\n" "void main()\n" "{\n" - " fragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n" + " FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n" "}\n\0"; int main() @@ -31,14 +35,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 diff --git a/src/1.getting_started/2.5.hello_triangle_exercise3/hello_triangle_exercise3.cpp b/src/1.getting_started/2.5.hello_triangle_exercise3/hello_triangle_exercise3.cpp index 521d36e..af5471a 100644 --- a/src/1.getting_started/2.5.hello_triangle_exercise3/hello_triangle_exercise3.cpp +++ b/src/1.getting_started/2.5.hello_triangle_exercise3/hello_triangle_exercise3.cpp @@ -6,6 +6,10 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow *window); +// settings +const unsigned int SCR_WIDTH = 1280; +const unsigned int SCR_HEIGHT = 720; + const char *vertexShaderSource = "#version 330 core\n" "layout (location = 0) in vec3 aPos;\n" "void main()\n" @@ -13,16 +17,16 @@ const char *vertexShaderSource = "#version 330 core\n" " gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n" "}\0"; const char *fragmentShader1Source = "#version 330 core\n" - "out vec4 fragColor;\n" + "out vec4 FragColor;\n" "void main()\n" "{\n" - " fragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n" + " FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n" "}\n\0"; const char *fragmentShader2Source = "#version 330 core\n" - "out vec4 fragColor;\n" + "out vec4 FragColor;\n" "void main()\n" "{\n" - " fragColor = vec4(1.0f, 1.0f, 0.0f, 1.0f);\n" + " FragColor = vec4(1.0f, 1.0f, 0.0f, 1.0f);\n" "}\n\0"; @@ -38,14 +42,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 diff --git a/src/1.getting_started/3.1.shaders_uniform/shaders_uniform.cpp b/src/1.getting_started/3.1.shaders_uniform/shaders_uniform.cpp index 0a703da..d4b3139 100644 --- a/src/1.getting_started/3.1.shaders_uniform/shaders_uniform.cpp +++ b/src/1.getting_started/3.1.shaders_uniform/shaders_uniform.cpp @@ -6,6 +6,10 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow *window); +// settings +const unsigned int SCR_WIDTH = 1280; +const unsigned int SCR_HEIGHT = 720; + const char *vertexShaderSource ="#version 330 core\n" "layout (location = 0) in vec3 aPos;\n" "void main()\n" @@ -14,11 +18,11 @@ const char *vertexShaderSource ="#version 330 core\n" "}\0"; const char *fragmentShaderSource = "#version 330 core\n" - "out vec4 fragColor;\n" + "out vec4 FragColor;\n" "uniform vec4 ourColor;\n" "void main()\n" "{\n" - " fragColor = ourColor;\n" + " FragColor = ourColor;\n" "}\n\0"; int main() @@ -34,13 +38,13 @@ int main() // glfw window creation // -------------------- GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL); - glfwMakeContextCurrent(window); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } + glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); // glad: load all OpenGL function pointers @@ -51,7 +55,6 @@ int main() return -1; } - // build and compile our shader program // ------------------------------------ // vertex shader diff --git a/src/1.getting_started/3.2.shaders_interpolation/shaders_interpolation.cpp b/src/1.getting_started/3.2.shaders_interpolation/shaders_interpolation.cpp index fec6bec..e4ad10f 100644 --- a/src/1.getting_started/3.2.shaders_interpolation/shaders_interpolation.cpp +++ b/src/1.getting_started/3.2.shaders_interpolation/shaders_interpolation.cpp @@ -6,6 +6,10 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow *window); +// settings +const unsigned int SCR_WIDTH = 1280; +const unsigned int SCR_HEIGHT = 720; + const char *vertexShaderSource ="#version 330 core\n" "layout (location = 0) in vec3 aPos;\n" "layout (location = 1) in vec3 aColor;\n" @@ -17,11 +21,11 @@ const char *vertexShaderSource ="#version 330 core\n" "}\0"; const char *fragmentShaderSource = "#version 330 core\n" - "out vec4 fragColor;\n" + "out vec4 FragColor;\n" "in vec3 ourColor;\n" "void main()\n" "{\n" - " fragColor = vec4(ourColor, 1.0f);\n" + " FragColor = vec4(ourColor, 1.0f);\n" "}\n\0"; int main() @@ -36,14 +40,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 @@ -54,7 +58,6 @@ int main() return -1; } - // build and compile our shader program // ------------------------------------ // vertex shader diff --git a/src/1.getting_started/3.3.shaders_class/3.3.shader.fs b/src/1.getting_started/3.3.shaders_class/3.3.shader.fs index 9f10653..bde012b 100644 --- a/src/1.getting_started/3.3.shaders_class/3.3.shader.fs +++ b/src/1.getting_started/3.3.shaders_class/3.3.shader.fs @@ -1,9 +1,9 @@ #version 330 core -out vec4 fragColor; +out vec4 FragColor; in vec3 ourColor; void main() { - fragColor = vec4(ourColor, 1.0f); + FragColor = vec4(ourColor, 1.0f); } \ No newline at end of file diff --git a/src/1.getting_started/3.3.shaders_class/3.3.shader.vs b/src/1.getting_started/3.3.shaders_class/3.3.shader.vs index a69d96b..feb3bfc 100644 --- a/src/1.getting_started/3.3.shaders_class/3.3.shader.vs +++ b/src/1.getting_started/3.3.shaders_class/3.3.shader.vs @@ -6,6 +6,6 @@ out vec3 ourColor; void main() { - gl_Position = vec4(aPos, 1.0f); + gl_Position = vec4(aPos, 1.0); ourColor = aColor; } \ No newline at end of file diff --git a/src/1.getting_started/3.3.shaders_class/shaders_class.cpp b/src/1.getting_started/3.3.shaders_class/shaders_class.cpp index f69223c..dcb90e3 100644 --- a/src/1.getting_started/3.3.shaders_class/shaders_class.cpp +++ b/src/1.getting_started/3.3.shaders_class/shaders_class.cpp @@ -8,6 +8,10 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow *window); +// settings +const unsigned int SCR_WIDTH = 1280; +const unsigned int SCR_HEIGHT = 720; + int main() { // glfw: initialize and configure @@ -20,14 +24,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 @@ -38,7 +42,6 @@ int main() return -1; } - // build and compile our shader program // ------------------------------------ Shader ourShader("3.3.shader.vs", "3.3.shader.fs"); // you can name your shader files however you like @@ -50,7 +53,6 @@ int main() 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom right -0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // bottom left 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f // top - }; unsigned int VBO, VAO; diff --git a/src/1.getting_started/4.1.textures/textures.cpp b/src/1.getting_started/4.1.textures/textures.cpp index 85ebb85..1a96c88 100644 --- a/src/1.getting_started/4.1.textures/textures.cpp +++ b/src/1.getting_started/4.1.textures/textures.cpp @@ -10,6 +10,10 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow *window); +// settings +const unsigned int SCR_WIDTH = 1280; +const unsigned int SCR_HEIGHT = 720; + int main() { // glfw: initialize and configure @@ -22,14 +26,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 @@ -93,8 +97,8 @@ 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; - unsigned char *data = stbi_load(FileSystem::getPath("resources/textures/container.jpg").c_str(), &width, &height, &nrComponents, 0); + int width, height, nrChannels; + 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); diff --git a/src/1.getting_started/4.2.textures_combined/textures_combined.cpp b/src/1.getting_started/4.2.textures_combined/textures_combined.cpp index dde3a54..b84ff14 100644 --- a/src/1.getting_started/4.2.textures_combined/textures_combined.cpp +++ b/src/1.getting_started/4.2.textures_combined/textures_combined.cpp @@ -10,6 +10,10 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow *window); +// settings +const unsigned int SCR_WIDTH = 1280; +const unsigned int SCR_HEIGHT = 720; + int main() { // glfw: initialize and configure @@ -22,14 +26,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 @@ -95,9 +99,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); @@ -119,7 +123,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/4.3.textures_exercise2/textures_exercise2.cpp b/src/1.getting_started/4.3.textures_exercise2/textures_exercise2.cpp index 362eecd..1d47272 100644 --- a/src/1.getting_started/4.3.textures_exercise2/textures_exercise2.cpp +++ b/src/1.getting_started/4.3.textures_exercise2/textures_exercise2.cpp @@ -10,6 +10,10 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow *window); +// settings +const unsigned int SCR_WIDTH = 1280; +const unsigned int SCR_HEIGHT = 720; + int main() { // glfw: initialize and configure @@ -22,14 +26,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 @@ -40,7 +44,6 @@ int main() return -1; } - // build and compile our shader zprogram // ------------------------------------ Shader ourShader("4.2.texture_combined.vs", "4.2.texture_combined.fs"); @@ -96,9 +99,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); @@ -120,7 +123,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 @@ -142,7 +145,6 @@ int main() ourShader.setInt("texture2", 1); - // render loop // ----------- while (!glfwWindowShouldClose(window)) diff --git a/src/1.getting_started/4.4.textures_exercise3/textures_exercise3.cpp b/src/1.getting_started/4.4.textures_exercise3/textures_exercise3.cpp index 26f884e..8fd1525 100644 --- a/src/1.getting_started/4.4.textures_exercise3/textures_exercise3.cpp +++ b/src/1.getting_started/4.4.textures_exercise3/textures_exercise3.cpp @@ -10,6 +10,10 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow *window); +// settings +const unsigned int SCR_WIDTH = 1280; +const unsigned int SCR_HEIGHT = 720; + int main() { // glfw: initialize and configure @@ -22,14 +26,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 @@ -40,7 +44,6 @@ int main() return -1; } - // build and compile our shader zprogram // ------------------------------------ Shader ourShader("4.2.texture_combined.vs", "4.2.texture_combined.fs"); @@ -49,8 +52,8 @@ int main() // ------------------------------------------------------------------ float vertices[] = { // positions // colors // texture coords (note that we changed them to 'zoom in' on our texture image) - 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.55f, 0.55f, // top right - 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.55f, 0.45f, // bottom right + 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.55f, 0.55f, // top right + 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.55f, 0.45f, // bottom right -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.45f, 0.45f, // bottom left -0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.45f, 0.55f // top left }; @@ -96,9 +99,9 @@ int main() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // set texture filtering to nearest neighbor to clearly see the texels/pixels glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // 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); @@ -120,7 +123,7 @@ int main() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // set texture filtering to nearest neighbor to clearly see the texels/pixels glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // 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 @@ -136,13 +139,12 @@ int main() // tell opengl for each sampler to which texture unit it belongs to (only has to be done once) // ------------------------------------------------------------------------------------------- ourShader.use(); // don't forget to activate/use the shader before setting uniforms! - // either set it manually like so: + // either set it manually like so: glUniform1i(glGetUniformLocation(ourShader.ID, "texture1"), 0); // or set it via the texture class ourShader.setInt("texture2", 1); - // render loop // ----------- while (!glfwWindowShouldClose(window)) diff --git a/src/1.getting_started/4.5.textures_exercise4/textures_exercise4.cpp b/src/1.getting_started/4.5.textures_exercise4/textures_exercise4.cpp index 28846f8..13bb81f 100644 --- a/src/1.getting_started/4.5.textures_exercise4/textures_exercise4.cpp +++ b/src/1.getting_started/4.5.textures_exercise4/textures_exercise4.cpp @@ -10,6 +10,10 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow *window); +// settings +const unsigned int SCR_WIDTH = 1280; +const unsigned int SCR_HEIGHT = 720; + // stores how much we're seeing of either texture float mixValue = 0.2f; @@ -25,14 +29,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 @@ -99,9 +103,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 +127,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 @@ -145,7 +149,6 @@ int main() ourShader.setInt("texture2", 1); - // render loop // ----------- while (!glfwWindowShouldClose(window))