dungeon_crawler
view prototype/src/texture.cc @ 63:7f52d6310317
fixed design issue with datafile_path
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 02 Oct 2012 04:52:59 +0300 |
parents | |
children |
line source
1 #include "opengl.h"
2 #include "imago2.h"
3 #include "texture.h"
5 unsigned int load_texture(const char *fname)
6 {
7 struct img_pixmap img;
9 img_init(&img);
10 if(img_load(&img, fname) == -1) {
11 img_destroy(&img);
12 return 0;
13 }
15 unsigned int intfmt = img_glintfmt(&img);
16 unsigned int fmt = img_glfmt(&img);
17 unsigned int type = img_gltype(&img);
19 unsigned int tex;
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_TEXTURE_WRAP_S, GL_REPEAT);
25 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
27 if(GLEW_SGIS_generate_mipmap) {
28 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
29 glTexImage2D(GL_TEXTURE_2D, 0, intfmt, img.width, img.height, 0, fmt, type, img.pixels);
30 } else {
31 gluBuild2DMipmaps(GL_TEXTURE_2D, intfmt, img.width, img.height, fmt, type, img.pixels);
32 }
34 img_destroy(&img);
35 return tex;
36 }
38 void destroy_texture(unsigned int tex)
39 {
40 glDeleteTextures(1, &tex);
41 }