no clue :) just to push it
[demo] / src / texture.cc
1 #include <string.h>
2 #include "texture.h"
3
4 Texture::Texture()
5 {
6 }
7
8 Texture::~Texture()
9 {
10 }
11
12 bool Texture::load(const char *fname)
13 {
14         Image img;
15
16         if(img.load(fname)) {
17                 images.clear();
18                 images.push_back(img);
19
20                 update();
21                 return true;
22         }
23
24         printf("%s NOT LOADED\n", fname);
25         /* check if it is a cubemap */
26         return load_cubemap(fname);
27 }
28
29 bool Texture::load_cubemap(const char *fname)
30 {
31         const char *suffixes[] = {
32                 "_px", "_py", "_pz",
33                 "_nx", "_ny", "_nz"
34         };
35
36         for(int i=0; i<6; i++) {
37                 char *buf = new char[strlen(fname) + 3 + 1];
38                 strcpy(buf, fname);
39                 char *suffix = strrchr(buf, '.');
40
41                 if(suffix) {
42                         memmove(suffix + 3, suffix, strlen(suffix) + 1);
43                         memcpy(suffix, suffixes[i], 3);
44                 }
45                 else {
46                         strcat(buf, suffixes[i]);
47                 }
48
49                 Image img;
50                 if(!img.load(buf)) {
51                         images.clear();
52                         return false;
53                 }
54                 images.push_back(img);
55         }
56
57         update();
58         return true;
59 }
60
61 bool Texture::is_cubemap() const
62 {
63         return (images.size() > 1);
64 }