nuclear@39: /* nuclear@39: Stereoscopic tunnel for iOS. nuclear@39: Copyright (C) 2011 John Tsiombikas nuclear@39: nuclear@39: This program is free software: you can redistribute it and/or modify nuclear@39: it under the terms of the GNU General Public License as published by nuclear@39: the Free Software Foundation, either version 3 of the License, or nuclear@39: (at your option) any later version. nuclear@39: nuclear@39: This program is distributed in the hope that it will be useful, nuclear@39: but WITHOUT ANY WARRANTY; without even the implied warranty of nuclear@39: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the nuclear@39: GNU General Public License for more details. nuclear@39: nuclear@39: You should have received a copy of the GNU General Public License nuclear@39: along with this program. If not, see . nuclear@39: */ nuclear@39: nuclear@14: #include nuclear@14: #include nuclear@14: #include nuclear@14: #include nuclear@14: #include "opengl.h" nuclear@14: #include "tex.h" nuclear@15: #include "config.h" nuclear@26: #include "imago2.h" nuclear@14: nuclear@14: unsigned int load_texture(const char *fname) nuclear@14: { nuclear@26: int xsz, ysz; nuclear@14: unsigned int tex; nuclear@26: void *pixels; nuclear@14: nuclear@27: if(!fname) { nuclear@27: return 0; nuclear@27: } nuclear@26: if(!(pixels = img_load_pixels(fname, &xsz, &ysz, IMG_FMT_RGBA32))) { nuclear@26: fprintf(stderr, "failed to load image: %s\n", fname); nuclear@14: return 0; nuclear@14: } nuclear@14: nuclear@14: glGenTextures(1, &tex); nuclear@14: glBindTexture(GL_TEXTURE_2D, tex); nuclear@14: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); nuclear@14: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); nuclear@14: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); nuclear@14: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); nuclear@25: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, xsz, ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); nuclear@26: img_free_pixels(pixels); nuclear@14: nuclear@14: return tex; nuclear@14: } nuclear@15: nuclear@15: void bind_texture(unsigned int tex, int unit) nuclear@15: { nuclear@15: glActiveTexture(GL_TEXTURE0 + unit); nuclear@15: nuclear@15: #ifndef IPHONE nuclear@15: if(tex) { nuclear@15: glEnable(GL_TEXTURE_2D); nuclear@15: } else { nuclear@15: glDisable(GL_TEXTURE_2D); nuclear@15: } nuclear@15: #endif nuclear@15: nuclear@15: glBindTexture(GL_TEXTURE_2D, tex); nuclear@15: }