Allow to set mirror repeat on textures, move texture loading into global scope

This commit is contained in:
Peder Bergebakken Sundt 2019-03-16 00:07:54 +01:00
parent 4a9653642e
commit 3141f6aca0
4 changed files with 10 additions and 15 deletions

View File

@ -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();

View File

@ -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);

View File

@ -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);