dbf-udg

diff src/texture.c @ 3:403ec1be3a1a

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 11 Jan 2013 22:52:56 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/texture.c	Fri Jan 11 22:52:56 2013 +0200
     1.3 @@ -0,0 +1,31 @@
     1.4 +#include <stdio.h>
     1.5 +#include "opengl.h"
     1.6 +#include <imago2.h>
     1.7 +#include "texture.h"
     1.8 +
     1.9 +unsigned int load_texture(const char *fname)
    1.10 +{
    1.11 +	int xsz, ysz;
    1.12 +	void *pixels;
    1.13 +	unsigned int tex;
    1.14 +
    1.15 +	if(!(pixels = img_load_pixels(fname, &xsz, &ysz, IMG_FMT_RGB24))) {
    1.16 +		fprintf(stderr, "failed to load texture: %s\n", fname);
    1.17 +		return 0;
    1.18 +	}
    1.19 +
    1.20 +	glGenTextures(1, &tex);
    1.21 +	glBindTexture(GL_TEXTURE_2D, tex);
    1.22 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    1.23 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    1.24 +	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, xsz, ysz, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
    1.25 +
    1.26 +	img_free_pixels(pixels);
    1.27 +
    1.28 +	return tex;
    1.29 +}
    1.30 +
    1.31 +void free_texture(unsigned int tex)
    1.32 +{
    1.33 +	glDeleteTextures(1, &tex);
    1.34 +}