dungeon_crawler

annotate prototype/src/texman.cc @ 31:ddb68dc4ba07

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