dungeon_crawler

diff prototype/src/texture.cc @ 48:aa9e28670ae2

added sound playback, more to do
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 17 Sep 2012 08:40:59 +0300
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/prototype/src/texture.cc	Mon Sep 17 08:40:59 2012 +0300
     1.3 @@ -0,0 +1,41 @@
     1.4 +#include "opengl.h"
     1.5 +#include "imago2.h"
     1.6 +#include "texture.h"
     1.7 +
     1.8 +unsigned int load_texture(const char *fname)
     1.9 +{
    1.10 +	struct img_pixmap img;
    1.11 +
    1.12 +	img_init(&img);
    1.13 +	if(img_load(&img, fname) == -1) {
    1.14 +		img_destroy(&img);
    1.15 +		return 0;
    1.16 +	}
    1.17 +
    1.18 +	unsigned int intfmt = img_glintfmt(&img);
    1.19 +	unsigned int fmt = img_glfmt(&img);
    1.20 +	unsigned int type = img_gltype(&img);
    1.21 +
    1.22 +	unsigned int tex;
    1.23 +	glGenTextures(1, &tex);
    1.24 +	glBindTexture(GL_TEXTURE_2D, tex);
    1.25 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    1.26 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    1.27 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    1.28 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    1.29 +
    1.30 +	if(GLEW_SGIS_generate_mipmap) {
    1.31 +		glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
    1.32 +		glTexImage2D(GL_TEXTURE_2D, 0, intfmt, img.width, img.height, 0, fmt, type, img.pixels);
    1.33 +	} else {
    1.34 +		gluBuild2DMipmaps(GL_TEXTURE_2D, intfmt, img.width, img.height, fmt, type, img.pixels);
    1.35 +	}
    1.36 +
    1.37 +	img_destroy(&img);
    1.38 +	return tex;
    1.39 +}
    1.40 +
    1.41 +void destroy_texture(unsigned int tex)
    1.42 +{
    1.43 +	glDeleteTextures(1, &tex);
    1.44 +}