istereo2

view src/tex.c @ 14:018f997dc646

button done
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 29 Sep 2015 01:11:54 +0300
parents
children 9d53a4938ce8
line source
1 /*
2 Stereoscopic tunnel for iOS.
3 Copyright (C) 2011 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <errno.h>
23 #include "opengl.h"
24 #include "tex.h"
25 #include "config.h"
26 #include "imago2.h"
28 unsigned int load_texture(const char *fname)
29 {
30 int xsz, ysz;
31 unsigned int tex;
32 void *pixels;
34 if(!fname) {
35 return 0;
36 }
37 if(!(pixels = img_load_pixels(fname, &xsz, &ysz, IMG_FMT_RGBA32))) {
38 fprintf(stderr, "failed to load image: %s\n", fname);
39 return 0;
40 }
42 glGenTextures(1, &tex);
43 glBindTexture(GL_TEXTURE_2D, tex);
44 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
45 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
46 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
47 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
48 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, xsz, ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
49 img_free_pixels(pixels);
51 return tex;
52 }
54 void bind_texture(unsigned int tex, int unit)
55 {
56 glActiveTexture(GL_TEXTURE0 + unit);
58 #ifndef IPHONE
59 if(tex) {
60 glEnable(GL_TEXTURE_2D);
61 } else {
62 glDisable(GL_TEXTURE_2D);
63 }
64 #endif
66 glBindTexture(GL_TEXTURE_2D, tex);
67 }