istereo

changeset 25:206348366635

trying to figure out why the textures are looking crappy on ipod
author John Tsiombikas <nuclear@mutantstargoat.com>
date Thu, 08 Sep 2011 04:23:56 +0300
parents 70309d71c899
children 862a3329a8f0
files src/istereo.c src/tex.c
diffstat 2 files changed, 20 insertions(+), 10 deletions(-) [+]
line diff
     1.1 --- a/src/istereo.c	Thu Sep 08 03:06:46 2011 +0300
     1.2 +++ b/src/istereo.c	Thu Sep 08 04:23:56 2011 +0300
     1.3 @@ -51,7 +51,7 @@
     1.4  		return -1;
     1.5  	}
     1.6  
     1.7 -	cam_fov(43.0);
     1.8 +	cam_fov(42.0);
     1.9  
    1.10  	return 0;
    1.11  }
     2.1 --- a/src/tex.c	Thu Sep 08 03:06:46 2011 +0300
     2.2 +++ b/src/tex.c	Thu Sep 08 04:23:56 2011 +0300
     2.3 @@ -10,8 +10,8 @@
     2.4  {
     2.5  	unsigned int tex;
     2.6  	FILE *fp;
     2.7 -	void *pixels;
     2.8 -	int xsz, ysz, sz;
     2.9 +	unsigned char *pixels;
    2.10 +	int xsz, ysz, sz, i;
    2.11  	char buf[512];
    2.12  
    2.13  	if(!(fp = fopen(fname, "r"))) {
    2.14 @@ -31,17 +31,27 @@
    2.15  	}
    2.16  	fgets(buf, sizeof buf, fp);
    2.17  
    2.18 -	sz = xsz * ysz * 3;
    2.19 +	sz = xsz * ysz * 4;
    2.20  	if(!(pixels = malloc(sz))) {
    2.21  		fprintf(stderr, "failed to allocate %d bytes\n", sz);
    2.22  		fclose(fp);
    2.23  		return 0;
    2.24  	}
    2.25 -	if(fread(pixels, 1, xsz * ysz * 3, fp) < sz) {
    2.26 -		fprintf(stderr, "partial read: %s\n", fname);
    2.27 -		free(pixels);
    2.28 -		fclose(fp);
    2.29 -		return 0;
    2.30 +	for(i=0; i<sz; i++) {
    2.31 +		int c;
    2.32 +
    2.33 +		if(i % 4 == 3) {
    2.34 +			pixels[i] = 255;
    2.35 +			continue;
    2.36 +		}
    2.37 +
    2.38 +		if((c = fgetc(fp)) == -1) {
    2.39 +			fprintf(stderr, "partial read: %s\n", fname);
    2.40 +			free(pixels);
    2.41 +			fclose(fp);
    2.42 +			return 0;
    2.43 +		}
    2.44 +		pixels[i] = c;
    2.45  	}
    2.46  	fclose(fp);
    2.47  
    2.48 @@ -51,7 +61,7 @@
    2.49  	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    2.50  	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    2.51  	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    2.52 -	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, xsz, ysz, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
    2.53 +	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, xsz, ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
    2.54  	free(pixels);
    2.55  
    2.56  	return tex;