dungeon_crawler

annotate prototype/src/texture.cc @ 61:4472ef41a209

forgot an extra mrt uniform in deferred_omni.p.glsl
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 25 Sep 2012 06:37:56 +0300
parents
children
rev   line source
nuclear@48 1 #include "opengl.h"
nuclear@48 2 #include "imago2.h"
nuclear@48 3 #include "texture.h"
nuclear@48 4
nuclear@48 5 unsigned int load_texture(const char *fname)
nuclear@48 6 {
nuclear@48 7 struct img_pixmap img;
nuclear@48 8
nuclear@48 9 img_init(&img);
nuclear@48 10 if(img_load(&img, fname) == -1) {
nuclear@48 11 img_destroy(&img);
nuclear@48 12 return 0;
nuclear@48 13 }
nuclear@48 14
nuclear@48 15 unsigned int intfmt = img_glintfmt(&img);
nuclear@48 16 unsigned int fmt = img_glfmt(&img);
nuclear@48 17 unsigned int type = img_gltype(&img);
nuclear@48 18
nuclear@48 19 unsigned int tex;
nuclear@48 20 glGenTextures(1, &tex);
nuclear@48 21 glBindTexture(GL_TEXTURE_2D, tex);
nuclear@48 22 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
nuclear@48 23 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
nuclear@48 24 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
nuclear@48 25 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
nuclear@48 26
nuclear@48 27 if(GLEW_SGIS_generate_mipmap) {
nuclear@48 28 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
nuclear@48 29 glTexImage2D(GL_TEXTURE_2D, 0, intfmt, img.width, img.height, 0, fmt, type, img.pixels);
nuclear@48 30 } else {
nuclear@48 31 gluBuild2DMipmaps(GL_TEXTURE_2D, intfmt, img.width, img.height, fmt, type, img.pixels);
nuclear@48 32 }
nuclear@48 33
nuclear@48 34 img_destroy(&img);
nuclear@48 35 return tex;
nuclear@48 36 }
nuclear@48 37
nuclear@48 38 void destroy_texture(unsigned int tex)
nuclear@48 39 {
nuclear@48 40 glDeleteTextures(1, &tex);
nuclear@48 41 }