dungeon_crawler

view prototype/src/texman.cc @ 35:d0e93b4d9ec9

normal mapping
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 28 Aug 2012 06:28:22 +0300
parents
children 3fef65352b0b
line source
1 #include <string.h>
2 #include "opengl.h"
3 #include "imago2.h"
4 #include "texman.h"
5 #include "datapath.h"
7 TextureSet::~TextureSet()
8 {
9 for(auto iter : textures) {
10 glDeleteTextures(1, &iter.second);
11 }
12 }
14 unsigned int TextureSet::get_texture(const char *fname) const
15 {
16 auto iter = textures.find(fname);
17 if(iter != textures.end()) {
18 return iter->second;
19 }
21 const char *path, *slash;
22 if((slash = strrchr(fname, '/'))) {
23 path = slash + 1;
24 }
25 path = datafile_path(path);
27 printf("loading texture: %s\n", path);
28 unsigned int tex = img_gltexture_load(path);
29 if(tex) {
30 textures[fname] = tex;
31 } else {
32 fprintf(stderr, "failed to load texture: %s\n", path);
33 }
34 return tex;
35 }