#define STBI_FAILURE_USERMSG #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" #include "Base.h" #ifndef TEXTURE_HANDLER #define TEXTURE_HANDLER class TextureHandler { private: int width = -1; int height = -1; int comp = -1; unsigned char* imageData; unsigned char* imageData1; public: GLuint texture; unsigned char* loadTexture(char* filename) { return stbi_load(filename, &width, &height, &comp, 0); } void loadAllTextures() { int textureIndex = 0; imageData = loadTexture("data/img/texturemap.png"); 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_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData); } int getTextureForNode(int x, int y, int z) { //Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z); if(blockManager.getNodeAt(x, y, z) == 1) { return 1; } else if(blockManager.getNodeAt(x, y, z) == 2) { return 2; } else if(blockManager.getNodeAt(x, y, z) == 3) { return 4; } else if(blockManager.getNodeAt(x, y, z) == 12) { return 81; } else if(blockManager.getNodeAt(x, y, z) == 13) { return 113; } else if(blockManager.getNodeAt(x, y, z) == 20) { return 17; } } }; #endif