X-Git-Url: http://git.mutantstargoat.com?p=demo;a=blobdiff_plain;f=src%2Ftexture.cc;h=bbebd7fbaa2c95d248334edfc615f69b8efee336;hp=624edc297f76470df2f2e8de31f8acc0eaae643c;hb=77e44c5424bd5e6e7c6a706151fa786a56270e12;hpb=697231b0832d626b328fc9ae4a5a5ef9a003aa1a diff --git a/src/texture.cc b/src/texture.cc index 624edc2..bbebd7f 100644 --- a/src/texture.cc +++ b/src/texture.cc @@ -1,25 +1,62 @@ -#include "imago2.h" +#include #include "texture.h" Texture::Texture() { - w = 0; - h = 0; - - pixels = 0; } Texture::~Texture() { - img_free_pixels(pixels); } bool Texture::load(const char *fname) { - if(!(pixels = (unsigned char *)img_load_pixels(fname, &w, &h))) { - fprintf(stderr, "Failed to load pixels from file: %s.\n", fname); - return false; + Image img; + + if(img.load(fname)) { + images.clear(); + images.push_back(img); + + update(); + return true; } + + /* check if it is a cubemap */ + return load_cubemap(fname); +} + +bool Texture::load_cubemap(const char *fname) +{ + const char *suffixes[] = { + "_px", "_py", "_pz", + "_nx", "_ny", "_nz" + }; + + for(int i=0; i<6; i++) { + char *buf = new char[strlen(fname) + 3 + 1]; + strcpy(buf, fname); + char *suffix = strrchr(buf, '.'); + + if(suffix) { + memmove(suffix + 3, suffix, strlen(suffix) + 1); + memcpy(suffix, suffixes[i], 3); + } else { + strcat(buf, suffixes[i]); + } + + Image img; + if(!img.load(buf)) { + images.clear(); + return false; + } + images.push_back(img); + } + update(); return true; +} + +bool Texture::is_cubemap() const +{ + return images.size() > 1; } \ No newline at end of file