dbf-udg

view 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 source
1 #include <stdio.h>
2 #include "opengl.h"
3 #include <imago2.h>
4 #include "texture.h"
6 unsigned int load_texture(const char *fname)
7 {
8 int xsz, ysz;
9 void *pixels;
10 unsigned int tex;
12 if(!(pixels = img_load_pixels(fname, &xsz, &ysz, IMG_FMT_RGB24))) {
13 fprintf(stderr, "failed to load texture: %s\n", fname);
14 return 0;
15 }
17 glGenTextures(1, &tex);
18 glBindTexture(GL_TEXTURE_2D, tex);
19 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
20 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
21 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, xsz, ysz, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
23 img_free_pixels(pixels);
25 return tex;
26 }
28 void free_texture(unsigned int tex)
29 {
30 glDeleteTextures(1, &tex);
31 }