labyrinth

view src/texture.c @ 1:d46f0947a96d

added helpful comment
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 06 Feb 2015 00:34:04 +0200
parents
children c8826e5ebec1
line source
1 #include <stdio.h>
2 #include "texture.h"
3 #include "image.h"
4 #include "opengl.h"
6 #ifndef GL_GENERATE_MIPMAP_SGIS
7 #define GL_GENERATE_MIPMAP_SGIS 0x8191
8 #endif
10 unsigned int load_texture(const char *fname)
11 {
12 unsigned int tex;
13 struct image *img;
15 if(!(img = load_image(fname))) {
16 fprintf(stderr, "failed to load image: %s\n", fname);
17 return 0;
18 }
20 glGenTextures(1, &tex);
21 glBindTexture(GL_TEXTURE_2D, tex);
22 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
23 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
24 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
25 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img->width, img->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img->pixels);
26 free_image(img);
27 return tex;
28 }