#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 textures; GLuint textures1; unsigned char* loadTexture(char* filename) { return stbi_load(filename, &width, &height, &comp, 0); } void loadAllTextures() { int textureIndex = 0; imageData = loadTexture("data/img/grass.png"); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(1, &textures); glBindTexture(GL_TEXTURE_2D, textures); 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, 16, 16, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData); imageData1 = loadTexture("data/img/oak.png"); glGenTextures(1, &textures1); glBindTexture(GL_TEXTURE_2D, textures1); 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, 16, 16, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData1); } void getTextureForNode(int x, int y, int z) { //Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z); if(blockManager.getNodeAt(x, y, z) == 1) { glBindTexture(GL_TEXTURE_2D, textures); } else if(blockManager.getNodeAt(x, y, z) == 2) { glBindTexture(GL_TEXTURE_2D, textures1); } } }; #endif