-#include "imago2.h"
+#include <string.h>
#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;
}
+
+ printf("%s NOT LOADED\n", fname);
+ /* 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