diff --git a/imageAsset.h b/imageAsset.h index 54a4a8c..1701c21 100644 --- a/imageAsset.h +++ b/imageAsset.h @@ -5,15 +5,16 @@ namespace vb01{ struct ImageAsset : public Asset{ - ImageAsset(std::string path, u8 *image, int width, int height){ + ImageAsset(std::string path, u8 *image, int width, int height, int numChannels){ this->path = path; this->image = image; this->width = width; this->height = height; + this->numChannels = numChannels; } u8 *image; - int width, height; + int width, height, numChannels; }; } diff --git a/imageReader.cpp b/imageReader.cpp index 5a95612..c32d787 100644 --- a/imageReader.cpp +++ b/imageReader.cpp @@ -18,6 +18,6 @@ namespace vb01{ stbi_set_flip_vertically_on_load(flip); int width, height, numChannels; u8 *data = stbi_load(path.c_str(), &width, &height, &numChannels, 0); - return new ImageAsset(path, data, width, height); + return new ImageAsset(path, data, width, height, numChannels); } } diff --git a/texture.cpp b/texture.cpp index c97fdec..dd7c064 100755 --- a/texture.cpp +++ b/texture.cpp @@ -60,6 +60,16 @@ namespace vb01{ } } + void Texture::loadImageData(ImageAsset *asset, int i){ + width = asset->width; + height = asset->height; + + glGenTextures(1, &texture[i]); + glBindTexture(GL_TEXTURE_2D, texture[i]); + glTexImage2D(GL_TEXTURE_2D, 0, png ? GL_RGBA : GL_RGB, width, height, 0, png ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, asset->image); + glGenerateMipmap(GL_TEXTURE_2D); + } + void Texture::create2DTexture(bool flip){ mixRatio = .1; @@ -69,19 +79,12 @@ namespace vb01{ if(paths[i].substr(length - 4, string::npos) == ".png") png = true; - glGenTextures(1, &texture[i]); - glBindTexture(GL_TEXTURE_2D, texture[i]); + loadImageData((ImageAsset*)AssetManager::getSingleton()->getAsset(paths[i])); + 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_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - - ImageAsset *asset = (ImageAsset*)AssetManager::getSingleton()->getAsset(paths[i]); - width = asset->width; - height = asset->height; - - glTexImage2D(GL_TEXTURE_2D, 0, png ? GL_RGBA : GL_RGB, width, height, 0, png ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, asset->image); - glGenerateMipmap(GL_TEXTURE_2D); } } diff --git a/texture.h b/texture.h index beb1cb0..55f073d 100755 --- a/texture.h +++ b/texture.h @@ -10,6 +10,8 @@ #include FT_FREETYPE_H namespace vb01{ + struct ImageAsset; + class Texture : public Animatable{ public: ~Texture(); @@ -20,6 +22,7 @@ namespace vb01{ void select(int = 0, int = 0); void update(int = 0); void animate(float, KeyframeChannel); + void loadImageData(ImageAsset*, int = 0); inline u32* getTexture(int i = 0){return &(texture[i]);} inline std::string* getPath(){return paths;} inline int getNumFrames(){return numFrames;}