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