diff --git a/src/Engine/Engine.vcxproj b/src/Engine/Engine.vcxproj
index b9303aa..54a028d 100644
--- a/src/Engine/Engine.vcxproj
+++ b/src/Engine/Engine.vcxproj
@@ -157,6 +157,7 @@
+
diff --git a/src/Engine/Engine.vcxproj.filters b/src/Engine/Engine.vcxproj.filters
index 5826d2c..0fc3777 100644
--- a/src/Engine/Engine.vcxproj.filters
+++ b/src/Engine/Engine.vcxproj.filters
@@ -50,6 +50,9 @@
Header Files
+
+ Header Files
+
diff --git a/src/Engine/images/awesomeface.png b/src/Engine/images/awesomeface.png
new file mode 100644
index 0000000..9840caf
Binary files /dev/null and b/src/Engine/images/awesomeface.png differ
diff --git a/src/Engine/main.cpp b/src/Engine/main.cpp
index ae07152..b48f445 100644
--- a/src/Engine/main.cpp
+++ b/src/Engine/main.cpp
@@ -7,8 +7,8 @@
#include "shaders/Shader.h"
#include "util/stb_image.h"
-// Continue: https://learnopengl.com/Getting-started/Textures
-// Chapter: Texture Units
+// Continue: https://learnopengl.com/Getting-started/Transformations
+// Chapter: Not started
//
@@ -117,6 +117,7 @@ int main()
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// TEXTURES
+ stbi_set_flip_vertically_on_load(true); // because an image has 0 at top of y axis and opengl expects it to be on the botton, so if this is omitted, the image will be flipped
int width, height, nrChannels;
unsigned char* image = stbi_load("images/container.jpg", &width, &height, &nrChannels, 0);
if (!image)
@@ -125,25 +126,33 @@ int main()
stbi_image_free(image);
return -1; // it would be better to just use a default error image instead and make the error message a warning message instead
}
- unsigned int textureID;
- glGenTextures(1, &textureID);
- glBindTexture(GL_TEXTURE_2D, textureID);
+ unsigned int textureID_container;
+ glGenTextures(1, &textureID_container);
+ glBindTexture(GL_TEXTURE_2D, textureID_container);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
glGenerateMipmap(GL_TEXTURE_2D);
stbi_image_free(image);
- GLfloat texCoords[] = {
- 0.0f, 0.0f, // lower-left corner
- 1.0f, 0.0f, // lower-right corner
- 0.5f, 1.0f // top-center corner
- };
+ image = stbi_load("images/awesomeface.png", &width, &height, &nrChannels, 0);
+ if (!image)
+ {
+ std::cerr << "ERROR::IO::LOAD_TEXTURE";
+ stbi_image_free(image);
+ return -1; // it would be better to just use a default error image instead and make the error message a warning message instead
+ }
+ unsigned int textureID_face;
+ glGenTextures(1, &textureID_face);
+ glBindTexture(GL_TEXTURE_2D, textureID_face);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
+ glGenerateMipmap(GL_TEXTURE_2D);
+ stbi_image_free(image);
+
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // use nearest neighbour when zooming out
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // use bilinear when zooming in
-
// main loop
while(!glfwWindowShouldClose(window))
{
@@ -153,11 +162,17 @@ int main()
ProcessInput(window);
shader->Use();
+ shader->setInt("ourTexture1", 0);
+ shader->setInt("ourTexture2", 1);
//float time = glfwGetTime();
//float greenValue = (sin(time) / 2.0f) + 0.5f;
//shader->setFloat("ourColour", 0.0f, greenValue, 0.0f, 0.0f);
- glBindTexture(GL_TEXTURE_2D, textureID);
+ glActiveTexture(GL_TEXTURE0); // before binding texture, activate correct textre Unit (some drivers might show nothing if this is omitted)
+ glBindTexture(GL_TEXTURE_2D, textureID_container);
+ glActiveTexture(GL_TEXTURE0 + 1); // GL_TEXTURE0 + 1 == GL_TEXTURE1, this means looping over multiple units is easily possible
+ glBindTexture(GL_TEXTURE_2D, textureID_face);
+
glBindVertexArray(vertexArrayObject);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
diff --git a/src/Engine/shaders/default/default.frag b/src/Engine/shaders/default/default.frag
index fff70b5..c796848 100644
--- a/src/Engine/shaders/default/default.frag
+++ b/src/Engine/shaders/default/default.frag
@@ -4,9 +4,10 @@ out vec4 FragColor;
in vec3 ourColour;
in vec2 texCoord;
-uniform sampler2D ourTexture;
+uniform sampler2D ourTexture1;
+uniform sampler2D ourTexture2;
void main()
{
- FragColor = texture(ourTexture, texCoord) * vec4(ourColour, 1.0);
+ FragColor = mix(texture(ourTexture1, texCoord), texture(ourTexture2, texCoord), 0.2) * vec4(ourColour, 1.0);
}
\ No newline at end of file