From 3141f6aca0e0fab19b30c860a2f8c81719055e0c Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Sat, 16 Mar 2019 00:07:54 +0100 Subject: [PATCH] Allow to set mirror repeat on textures, move texture loading into global scope --- res/shaders/simple.frag | 2 +- src/gamelogic.cpp | 15 +++++---------- src/utilities/glutils.cpp | 6 +++--- src/utilities/glutils.h | 2 +- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/res/shaders/simple.frag b/res/shaders/simple.frag index cb20a63..f571640 100644 --- a/res/shaders/simple.frag +++ b/res/shaders/simple.frag @@ -101,5 +101,5 @@ void main() { } else { color = texture(diffuseTexture, UV); } - if (isInverted) color.rgb = 1- color.rgb; + if (isInverted) color.rgb = 1 - color.rgb; } diff --git a/src/gamelogic.cpp b/src/gamelogic.cpp index c6e421f..cd0f1ac 100644 --- a/src/gamelogic.cpp +++ b/src/gamelogic.cpp @@ -72,10 +72,11 @@ const float debug_startTime = 45; double totalElapsedTime = debug_startTime; // textures -PNGImage t_charmap; -PNGImage t_cobble_diff; -PNGImage t_cobble_normal; -PNGImage t_perlin; +PNGImage t_charmap = loadPNGFile("../res/textures/charmap.png"); +PNGImage t_cobble_diff = loadPNGFile("../res/textures/cobble_diff.png"); +PNGImage t_cobble_normal = loadPNGFile("../res/textures/cobble_normal.png"); +PNGImage t_perlin = makePerlinNoisePNG(1639*2, 44, {0.1, 0.2, 0.3}); + void mouseCallback(GLFWwindow* window, double x, double y) { int windowWidth, windowHeight; @@ -120,12 +121,6 @@ void initGame(GLFWwindow* window, CommandLineOptions gameOptions) { Mesh pad = generateBox(padDimensions.x, padDimensions.y, padDimensions.z, false); Mesh sphere = generateSphere(1.0, 40, 40); - // textures - t_charmap = loadPNGFile("../res/textures/charmap.png"); - t_cobble_diff = loadPNGFile("../res/textures/cobble_diff.png"); - t_cobble_normal = loadPNGFile("../res/textures/cobble_normal.png"); - t_perlin = makePerlinNoisePNG(1639*2, 44, {0.1, 0.2, 0.3}); - rootNode = createSceneNode(); boxNode = createSceneNode(NORMAL_TEXTURED_GEOMETRY); padNode = createSceneNode(); diff --git a/src/utilities/glutils.cpp b/src/utilities/glutils.cpp index 2c668d2..3bb327a 100644 --- a/src/utilities/glutils.cpp +++ b/src/utilities/glutils.cpp @@ -104,13 +104,13 @@ void addTangents(uint vaoID, Mesh& mesh) { glEnableVertexAttribArray(4); } -uint generateTexture(PNGImage& texture) { +uint generateTexture(PNGImage& texture, bool mirrored) { uint id; glGenTextures(1, &id); glBindTexture(GL_TEXTURE_2D, id); - 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, (mirrored) ? GL_MIRRORED_REPEAT : GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (mirrored) ? GL_MIRRORED_REPEAT : GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); diff --git a/src/utilities/glutils.h b/src/utilities/glutils.h index 3ad25fb..aa72d6e 100644 --- a/src/utilities/glutils.h +++ b/src/utilities/glutils.h @@ -8,4 +8,4 @@ unsigned int generateBuffer(Mesh &mesh, bool isNormalMapped = false); void addTangents(unsigned int vaoID, Mesh& mesh); -unsigned int generateTexture(PNGImage& texture); +unsigned int generateTexture(PNGImage& texture, bool mirrored = false);