dungeon_crawler

diff prototype/src/texman.cc @ 43:3fef65352b0b

- added mipmap generation
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 30 Aug 2012 05:58:09 +0300
parents e5567ddbf2ef
children f3030df27110
line diff
     1.1 --- a/prototype/src/texman.cc	Thu Aug 30 05:38:03 2012 +0300
     1.2 +++ b/prototype/src/texman.cc	Thu Aug 30 05:58:09 2012 +0300
     1.3 @@ -4,6 +4,8 @@
     1.4  #include "texman.h"
     1.5  #include "datapath.h"
     1.6  
     1.7 +unsigned int load_texture(const char *fname);
     1.8 +
     1.9  TextureSet::~TextureSet()
    1.10  {
    1.11  	for(auto iter : textures) {
    1.12 @@ -25,7 +27,7 @@
    1.13  	path = datafile_path(path);
    1.14  
    1.15  	printf("loading texture: %s\n", path);
    1.16 -	unsigned int tex = img_gltexture_load(path);
    1.17 +	unsigned int tex = load_texture(path);
    1.18  	if(tex) {
    1.19  		textures[fname] = tex;
    1.20  	} else {
    1.21 @@ -33,3 +35,36 @@
    1.22  	}
    1.23  	return tex;
    1.24  }
    1.25 +
    1.26 +unsigned int load_texture(const char *fname)
    1.27 +{
    1.28 +	struct img_pixmap img;
    1.29 +
    1.30 +	img_init(&img);
    1.31 +	if(img_load(&img, fname) == -1) {
    1.32 +		img_destroy(&img);
    1.33 +		return 0;
    1.34 +	}
    1.35 +
    1.36 +	unsigned int intfmt = img_glintfmt(&img);
    1.37 +	unsigned int fmt = img_glfmt(&img);
    1.38 +	unsigned int type = img_gltype(&img);
    1.39 +
    1.40 +	unsigned int tex;
    1.41 +	glGenTextures(1, &tex);
    1.42 +	glBindTexture(GL_TEXTURE_2D, tex);
    1.43 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    1.44 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    1.45 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    1.46 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    1.47 +
    1.48 +	if(GLEW_SGIS_generate_mipmap) {
    1.49 +		glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
    1.50 +		glTexImage2D(GL_TEXTURE_2D, 0, intfmt, img.width, img.height, 0, fmt, type, img.pixels);
    1.51 +	} else {
    1.52 +		gluBuild2DMipmaps(GL_TEXTURE_2D, intfmt, img.width, img.height, fmt, type, img.pixels);
    1.53 +	}
    1.54 +
    1.55 +	img_destroy(&img);
    1.56 +	return tex;
    1.57 +}