istereo

view src/tex.c @ 26:862a3329a8f0

wohooo, added a shitload of code from zlib/libpng/libjpeg. When the good lord was raining shared libraries the iphone held a fucking umbrella...
author John Tsiombikas <nuclear@mutantstargoat.com>
date Thu, 08 Sep 2011 06:28:38 +0300
parents 206348366635
children fd39c0198935
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(!(pixels = img_load_pixels(fname, &xsz, &ysz, IMG_FMT_RGBA32))) {
17 fprintf(stderr, "failed to load image: %s\n", fname);
18 return 0;
19 }
21 glGenTextures(1, &tex);
22 glBindTexture(GL_TEXTURE_2D, tex);
23 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
24 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
25 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
26 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
27 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, xsz, ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
28 img_free_pixels(pixels);
30 return tex;
31 }
33 void bind_texture(unsigned int tex, int unit)
34 {
35 glActiveTexture(GL_TEXTURE0 + unit);
37 #ifndef IPHONE
38 if(tex) {
39 glEnable(GL_TEXTURE_2D);
40 } else {
41 glDisable(GL_TEXTURE_2D);
42 }
43 #endif
45 glBindTexture(GL_TEXTURE_2D, tex);
46 }