dbf-udg
annotate src/texture.c @ 3:403ec1be3a1a
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 11 Jan 2013 22:52:56 +0200 |
parents | |
children |
rev | line source |
---|---|
nuclear@3 | 1 #include <stdio.h> |
nuclear@3 | 2 #include "opengl.h" |
nuclear@3 | 3 #include <imago2.h> |
nuclear@3 | 4 #include "texture.h" |
nuclear@3 | 5 |
nuclear@3 | 6 unsigned int load_texture(const char *fname) |
nuclear@3 | 7 { |
nuclear@3 | 8 int xsz, ysz; |
nuclear@3 | 9 void *pixels; |
nuclear@3 | 10 unsigned int tex; |
nuclear@3 | 11 |
nuclear@3 | 12 if(!(pixels = img_load_pixels(fname, &xsz, &ysz, IMG_FMT_RGB24))) { |
nuclear@3 | 13 fprintf(stderr, "failed to load texture: %s\n", fname); |
nuclear@3 | 14 return 0; |
nuclear@3 | 15 } |
nuclear@3 | 16 |
nuclear@3 | 17 glGenTextures(1, &tex); |
nuclear@3 | 18 glBindTexture(GL_TEXTURE_2D, tex); |
nuclear@3 | 19 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
nuclear@3 | 20 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
nuclear@3 | 21 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, xsz, ysz, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels); |
nuclear@3 | 22 |
nuclear@3 | 23 img_free_pixels(pixels); |
nuclear@3 | 24 |
nuclear@3 | 25 return tex; |
nuclear@3 | 26 } |
nuclear@3 | 27 |
nuclear@3 | 28 void free_texture(unsigned int tex) |
nuclear@3 | 29 { |
nuclear@3 | 30 glDeleteTextures(1, &tex); |
nuclear@3 | 31 } |