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 4a5f6f6..d37668e 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 @@ -7,8 +7,8 @@ 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 unsigned int SCR_WIDTH = 800; +const unsigned int SCR_HEIGHT = 600; int main() { 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 dd98fd4..39daa0f 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 @@ -7,8 +7,8 @@ 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 unsigned int SCR_WIDTH = 800; +const unsigned int SCR_HEIGHT = 600; int main() { 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 ecfb59c..4b5a1fd 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 @@ -7,8 +7,8 @@ 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 unsigned int SCR_WIDTH = 800; +const unsigned int SCR_HEIGHT = 600; const char *vertexShaderSource = "#version 330 core\n" "layout (location = 0) in vec3 aPos;\n" 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 47a846f..486c269 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 @@ -7,8 +7,8 @@ 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 unsigned int SCR_WIDTH = 800; +const unsigned int SCR_HEIGHT = 600; const char *vertexShaderSource = "#version 330 core\n" "layout (location = 0) in vec3 aPos;\n" 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 40ee6e9..2524cb6 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 @@ -7,8 +7,8 @@ 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 unsigned int SCR_WIDTH = 800; +const unsigned int SCR_HEIGHT = 600; const char *vertexShaderSource = "#version 330 core\n" "layout (location = 0) in vec3 aPos;\n" 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 7d57d7c..a51dd50 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 @@ -7,8 +7,8 @@ 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 unsigned int SCR_WIDTH = 800; +const unsigned int SCR_HEIGHT = 600; const char *vertexShaderSource = "#version 330 core\n" "layout (location = 0) in vec3 aPos;\n" 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 af5471a..45af9ee 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 @@ -7,8 +7,8 @@ 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 unsigned int SCR_WIDTH = 800; +const unsigned int SCR_HEIGHT = 600; const char *vertexShaderSource = "#version 330 core\n" "layout (location = 0) in vec3 aPos;\n" 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 d4b3139..ea4e33d 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 @@ -7,8 +7,8 @@ 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 unsigned int SCR_WIDTH = 800; +const unsigned int SCR_HEIGHT = 600; const char *vertexShaderSource ="#version 330 core\n" "layout (location = 0) in vec3 aPos;\n" 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 e4ad10f..8d2db9c 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 @@ -7,8 +7,8 @@ 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 unsigned int SCR_WIDTH = 800; +const unsigned int SCR_HEIGHT = 600; const char *vertexShaderSource ="#version 330 core\n" "layout (location = 0) in vec3 aPos;\n" 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 dcb90e3..d756da0 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 @@ -9,8 +9,8 @@ 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 unsigned int SCR_WIDTH = 800; +const unsigned int SCR_HEIGHT = 600; int main() { diff --git a/src/1.getting_started/4.1.textures/4.1.texture.fs b/src/1.getting_started/4.1.textures/4.1.texture.fs index b5fc5bc..d7bb364 100644 --- a/src/1.getting_started/4.1.textures/4.1.texture.fs +++ b/src/1.getting_started/4.1.textures/4.1.texture.fs @@ -1,13 +1,13 @@ #version 330 core -out vec4 fragColor; +out vec4 FragColor; in vec3 ourColor; -in vec2 texCoord; +in vec2 TexCoord; // texture sampler uniform sampler2D texture1; void main() { - fragColor = texture(texture1, texCoord); + FragColor = texture(texture1, TexCoord); } \ No newline at end of file diff --git a/src/1.getting_started/4.1.textures/4.1.texture.vs b/src/1.getting_started/4.1.textures/4.1.texture.vs index 7351c1e..4fd6603 100644 --- a/src/1.getting_started/4.1.textures/4.1.texture.vs +++ b/src/1.getting_started/4.1.textures/4.1.texture.vs @@ -4,11 +4,11 @@ layout (location = 1) in vec3 aColor; layout (location = 2) in vec2 aTexCoord; out vec3 ourColor; -out vec2 texCoord; +out vec2 TexCoord; void main() { - gl_Position = vec4(aPos, 1.0f); + gl_Position = vec4(aPos, 1.0); ourColor = aColor; - 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/4.1.textures/textures.cpp b/src/1.getting_started/4.1.textures/textures.cpp index 1a96c88..295b766 100644 --- a/src/1.getting_started/4.1.textures/textures.cpp +++ b/src/1.getting_started/4.1.textures/textures.cpp @@ -11,8 +11,8 @@ 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 unsigned int SCR_WIDTH = 800; +const unsigned int SCR_HEIGHT = 600; int main() { diff --git a/src/1.getting_started/4.2.textures_combined/4.2.texture.fs b/src/1.getting_started/4.2.textures_combined/4.2.texture.fs index c7652e0..9fef202 100644 --- a/src/1.getting_started/4.2.textures_combined/4.2.texture.fs +++ b/src/1.getting_started/4.2.textures_combined/4.2.texture.fs @@ -1,8 +1,8 @@ #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 +11,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/4.2.textures_combined/4.2.texture.vs b/src/1.getting_started/4.2.textures_combined/4.2.texture.vs index 7351c1e..4fd6603 100644 --- a/src/1.getting_started/4.2.textures_combined/4.2.texture.vs +++ b/src/1.getting_started/4.2.textures_combined/4.2.texture.vs @@ -4,11 +4,11 @@ layout (location = 1) in vec3 aColor; layout (location = 2) in vec2 aTexCoord; out vec3 ourColor; -out vec2 texCoord; +out vec2 TexCoord; void main() { - gl_Position = vec4(aPos, 1.0f); + gl_Position = vec4(aPos, 1.0); ourColor = aColor; - 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/4.2.textures_combined/textures_combined.cpp b/src/1.getting_started/4.2.textures_combined/textures_combined.cpp index b84ff14..3a04a3e 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 @@ -11,8 +11,8 @@ 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 unsigned int SCR_WIDTH = 800; +const unsigned int SCR_HEIGHT = 600; int main() { 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 1d47272..4c3936c 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 @@ -11,8 +11,8 @@ 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 unsigned int SCR_WIDTH = 800; +const unsigned int SCR_HEIGHT = 600; int main() { 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 8fd1525..419e716 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 @@ -11,8 +11,8 @@ 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 unsigned int SCR_WIDTH = 800; +const unsigned int SCR_HEIGHT = 600; int main() { diff --git a/src/1.getting_started/4.5.textures_exercise4/4.5.texture.fs b/src/1.getting_started/4.5.textures_exercise4/4.5.texture.fs index bf5ce11..33f51dd 100644 --- a/src/1.getting_started/4.5.textures_exercise4/4.5.texture.fs +++ b/src/1.getting_started/4.5.textures_exercise4/4.5.texture.fs @@ -1,8 +1,8 @@ #version 330 core -out vec4 fragColor; +out vec4 FragColor; in vec3 ourColor; -in vec2 texCoord; +in vec2 TexCoord; uniform float mixValue; @@ -13,5 +13,5 @@ uniform sampler2D texture2; void main() { // linearly interpolate between both textures - fragColor = mix(texture(texture1, texCoord), texture(texture2, texCoord), mixValue); + FragColor = mix(texture(texture1, TexCoord), texture(texture2, TexCoord), mixValue); } \ No newline at end of file diff --git a/src/1.getting_started/4.5.textures_exercise4/4.5.texture.vs b/src/1.getting_started/4.5.textures_exercise4/4.5.texture.vs index 7351c1e..4fd6603 100644 --- a/src/1.getting_started/4.5.textures_exercise4/4.5.texture.vs +++ b/src/1.getting_started/4.5.textures_exercise4/4.5.texture.vs @@ -4,11 +4,11 @@ layout (location = 1) in vec3 aColor; layout (location = 2) in vec2 aTexCoord; out vec3 ourColor; -out vec2 texCoord; +out vec2 TexCoord; void main() { - gl_Position = vec4(aPos, 1.0f); + gl_Position = vec4(aPos, 1.0); ourColor = aColor; - 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/4.5.textures_exercise4/textures_exercise4.cpp b/src/1.getting_started/4.5.textures_exercise4/textures_exercise4.cpp index 13bb81f..9359e85 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 @@ -11,8 +11,8 @@ 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 unsigned int SCR_WIDTH = 800; +const unsigned int SCR_HEIGHT = 600; // stores how much we're seeing of either texture float mixValue = 0.2f; diff --git a/src/1.getting_started/5.1.transformations/5.1.transform.fs b/src/1.getting_started/5.1.transformations/5.1.transform.fs index c7652e0..44839bc 100644 --- a/src/1.getting_started/5.1.transformations/5.1.transform.fs +++ b/src/1.getting_started/5.1.transformations/5.1.transform.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/5.1.transformations/5.1.transform.vs b/src/1.getting_started/5.1.transformations/5.1.transform.vs index 16c6e90..709bef9 100644 --- a/src/1.getting_started/5.1.transformations/5.1.transform.vs +++ b/src/1.getting_started/5.1.transformations/5.1.transform.vs @@ -1,16 +1,13 @@ #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 transform; void main() { - gl_Position = transform * vec4(aPos, 1.0f); - ourColor = aColor; - texCoord = vec2(aTexCoord.x, aTexCoord.y); + gl_Position = transform * vec4(aPos, 1.0); + TexCoord = vec2(aTexCoord.x, aTexCoord.y); } \ No newline at end of file diff --git a/src/1.getting_started/5.1.transformations/transformations.cpp b/src/1.getting_started/5.1.transformations/transformations.cpp index f99f6fe..3b84dab 100644 --- a/src/1.getting_started/5.1.transformations/transformations.cpp +++ b/src/1.getting_started/5.1.transformations/transformations.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/5.2.transformations_exercise2/transformations_exercise2.cpp b/src/1.getting_started/5.2.transformations_exercise2/transformations_exercise2.cpp index ec8e914..ea4af65 100644 --- a/src/1.getting_started/5.2.transformations_exercise2/transformations_exercise2.cpp +++ b/src/1.getting_started/5.2.transformations_exercise2/transformations_exercise2.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 @@ -184,7 +185,7 @@ int main() transform = glm::scale(transform, glm::vec3(scaleAmount, scaleAmount, scaleAmount)); glUniformMatrix4fv(transformLoc, 1, GL_FALSE, &transform[0][0]); // this time take the matrix value array's first element as its memory pointer value - // now with the uniform matrix being replaced with new transformations, draw it again. + // now with the uniform matrix being replaced with new transformations, draw it again. glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)