istereo

view src/tex.c @ 36:834503dcb486

fixed the rotated gui problem
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 09 Sep 2011 10:25:03 +0300
parents 862a3329a8f0
children ff055bff6a15
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <errno.h>
5 #include "opengl.h"
6 #include "tex.h"
7 #include "config.h"
8 #include "imago2.h"
10 unsigned int load_texture(const char *fname)
11 {
12 int xsz, ysz;
13 unsigned int tex;
14 void *pixels;
16 if(!fname) {
17 return 0;
18 }
19 if(!(pixels = img_load_pixels(fname, &xsz, &ysz, IMG_FMT_RGBA32))) {
20 fprintf(stderr, "failed to load image: %s\n", fname);
21 return 0;
22 }
24 glGenTextures(1, &tex);
25 glBindTexture(GL_TEXTURE_2D, tex);
26 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
27 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
28 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
29 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
30 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, xsz, ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
31 img_free_pixels(pixels);
33 return tex;
34 }
36 void bind_texture(unsigned int tex, int unit)
37 {
38 glActiveTexture(GL_TEXTURE0 + unit);
40 #ifndef IPHONE
41 if(tex) {
42 glEnable(GL_TEXTURE_2D);
43 } else {
44 glDisable(GL_TEXTURE_2D);
45 }
46 #endif
48 glBindTexture(GL_TEXTURE_2D, tex);
49 }