labyrinth

diff src/texture.c @ 0:8ba79034e8a6

labyrinth example initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 15 Jan 2015 14:59:38 +0200
parents
children c8826e5ebec1
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/texture.c	Thu Jan 15 14:59:38 2015 +0200
     1.3 @@ -0,0 +1,28 @@
     1.4 +#include <stdio.h>
     1.5 +#include "texture.h"
     1.6 +#include "image.h"
     1.7 +#include "opengl.h"
     1.8 +
     1.9 +#ifndef GL_GENERATE_MIPMAP_SGIS
    1.10 +#define GL_GENERATE_MIPMAP_SGIS 0x8191
    1.11 +#endif
    1.12 +
    1.13 +unsigned int load_texture(const char *fname)
    1.14 +{
    1.15 +	unsigned int tex;
    1.16 +	struct image *img;
    1.17 +
    1.18 +	if(!(img = load_image(fname))) {
    1.19 +		fprintf(stderr, "failed to load image: %s\n", fname);
    1.20 +		return 0;
    1.21 +	}
    1.22 +
    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_GENERATE_MIPMAP_SGIS, GL_TRUE);
    1.28 +	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img->width, img->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img->pixels);
    1.29 +	free_image(img);
    1.30 +	return tex;
    1.31 +}