istereo2

diff src/tex.c @ 2:81d35769f546

added the tunnel effect source
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 19 Sep 2015 05:51:51 +0300
parents
children 9d53a4938ce8
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/tex.c	Sat Sep 19 05:51:51 2015 +0300
     1.3 @@ -0,0 +1,67 @@
     1.4 +/*
     1.5 +Stereoscopic tunnel for iOS.
     1.6 +Copyright (C) 2011  John Tsiombikas <nuclear@member.fsf.org>
     1.7 +
     1.8 +This program is free software: you can redistribute it and/or modify
     1.9 +it under the terms of the GNU General Public License as published by
    1.10 +the Free Software Foundation, either version 3 of the License, or
    1.11 +(at your option) any later version.
    1.12 +
    1.13 +This program is distributed in the hope that it will be useful,
    1.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.16 +GNU General Public License for more details.
    1.17 +
    1.18 +You should have received a copy of the GNU General Public License
    1.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1.20 +*/
    1.21 +
    1.22 +#include <stdio.h>
    1.23 +#include <stdlib.h>
    1.24 +#include <string.h>
    1.25 +#include <errno.h>
    1.26 +#include "opengl.h"
    1.27 +#include "tex.h"
    1.28 +#include "config.h"
    1.29 +#include "imago2.h"
    1.30 +
    1.31 +unsigned int load_texture(const char *fname)
    1.32 +{
    1.33 +	int xsz, ysz;
    1.34 +	unsigned int tex;
    1.35 +	void *pixels;
    1.36 +
    1.37 +	if(!fname) {
    1.38 +		return 0;
    1.39 +	}
    1.40 +	if(!(pixels = img_load_pixels(fname, &xsz, &ysz, IMG_FMT_RGBA32))) {
    1.41 +		fprintf(stderr, "failed to load image: %s\n", fname);
    1.42 +		return 0;
    1.43 +	}
    1.44 +
    1.45 +	glGenTextures(1, &tex);
    1.46 +	glBindTexture(GL_TEXTURE_2D, tex);
    1.47 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    1.48 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    1.49 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    1.50 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    1.51 +	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, xsz, ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
    1.52 +	img_free_pixels(pixels);
    1.53 +
    1.54 +	return tex;
    1.55 +}
    1.56 +
    1.57 +void bind_texture(unsigned int tex, int unit)
    1.58 +{
    1.59 +	glActiveTexture(GL_TEXTURE0 + unit);
    1.60 +
    1.61 +#ifndef IPHONE
    1.62 +	if(tex) {
    1.63 +		glEnable(GL_TEXTURE_2D);
    1.64 +	} else {
    1.65 +		glDisable(GL_TEXTURE_2D);
    1.66 +	}
    1.67 +#endif
    1.68 +
    1.69 +	glBindTexture(GL_TEXTURE_2D, tex);
    1.70 +}