diff --git a/build/shaders/shader.fs b/build/shaders/shader.fs index 6e273bd..709d716 100644 --- a/build/shaders/shader.fs +++ b/build/shaders/shader.fs @@ -5,10 +5,9 @@ out vec4 FragColor; in vec3 ourColor; in vec2 TexCoord; -uniform sampler2D texture1; -uniform sampler2D texture2; +uniform sampler2D tex; void main() { - FragColor = texture(texture2, TexCoord); + FragColor = texture(tex, TexCoord); } diff --git a/build/src/main.cpp.o b/build/src/main.cpp.o index d000126..e2d68d5 100644 Binary files a/build/src/main.cpp.o and b/build/src/main.cpp.o differ diff --git a/build/untap b/build/untap index 2c1630b..0b65a4f 100755 Binary files a/build/untap and b/build/untap differ diff --git a/src/main.cpp b/src/main.cpp index 125340c..99fda50 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,47 +39,31 @@ int main() Shader myShader("shaders/shader.vs", "shaders/shader.fs"); texture_t tex; - tex.data = stbi_load("textures/container.jpg", &tex.width, &tex.height, &tex.nrChannels, 0); - unsigned int texture1; - glGenTextures(1, &texture1); - glBindTexture(GL_TEXTURE_2D, texture1); + stbi_set_flip_vertically_on_load(true); + + tex.data = stbi_load("textures/wg.jpg", &tex.width, &tex.height, &tex.nrChannels, 0); + + unsigned int texture; + glGenTextures(1, &texture); + glBindTexture(GL_TEXTURE_2D, texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + if (tex.data) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex.width, tex.height, 0, GL_RGB, GL_UNSIGNED_BYTE, tex.data); glGenerateMipmap(GL_TEXTURE_2D); } else { std::cout << "Failed to load texture\n"; } + + stbi_image_free(tex.data); - - stbi_set_flip_vertically_on_load(true); - tex.data = stbi_load("textures/wg.jpg", &tex.width, &tex.height, &tex.nrChannels, 0); - - unsigned int texture2; - glGenTextures(1, &texture2); - glBindTexture(GL_TEXTURE_2D, texture2); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - - if (tex.data) { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex.width, tex.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex.data); - glGenerateMipmap(GL_TEXTURE_2D); - } else { - std::cout << "Failed to load texture\n"; - } - - stbi_image_free(tex.data); - unsigned int VAO; glGenVertexArrays(1, &VAO); @@ -110,8 +94,7 @@ int main() glEnableVertexAttribArray(2); myShader.use(); - myShader.setInt("texture1", 0); - myShader.setInt("texture2", 1); + myShader.setInt("tex", 0); while(!glfwWindowShouldClose(window)) { @@ -125,9 +108,7 @@ int main() myShader.use(); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, texture1); - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, texture2); + glBindTexture(GL_TEXTURE_2D, texture); glBindVertexArray(VAO); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); diff --git a/src/shaders/shader.fs b/src/shaders/shader.fs index 6e273bd..709d716 100644 --- a/src/shaders/shader.fs +++ b/src/shaders/shader.fs @@ -5,10 +5,9 @@ out vec4 FragColor; in vec3 ourColor; in vec2 TexCoord; -uniform sampler2D texture1; -uniform sampler2D texture2; +uniform sampler2D tex; void main() { - FragColor = texture(texture2, TexCoord); + FragColor = texture(tex, TexCoord); }