istereo
diff src/tex.c @ 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 | 4c20f10a7183 |
children | 862a3329a8f0 |
line diff
1.1 --- a/src/tex.c Thu Sep 08 03:06:46 2011 +0300 1.2 +++ b/src/tex.c Thu Sep 08 04:23:56 2011 +0300 1.3 @@ -10,8 +10,8 @@ 1.4 { 1.5 unsigned int tex; 1.6 FILE *fp; 1.7 - void *pixels; 1.8 - int xsz, ysz, sz; 1.9 + unsigned char *pixels; 1.10 + int xsz, ysz, sz, i; 1.11 char buf[512]; 1.12 1.13 if(!(fp = fopen(fname, "r"))) { 1.14 @@ -31,17 +31,27 @@ 1.15 } 1.16 fgets(buf, sizeof buf, fp); 1.17 1.18 - sz = xsz * ysz * 3; 1.19 + sz = xsz * ysz * 4; 1.20 if(!(pixels = malloc(sz))) { 1.21 fprintf(stderr, "failed to allocate %d bytes\n", sz); 1.22 fclose(fp); 1.23 return 0; 1.24 } 1.25 - if(fread(pixels, 1, xsz * ysz * 3, fp) < sz) { 1.26 - fprintf(stderr, "partial read: %s\n", fname); 1.27 - free(pixels); 1.28 - fclose(fp); 1.29 - return 0; 1.30 + for(i=0; i<sz; i++) { 1.31 + int c; 1.32 + 1.33 + if(i % 4 == 3) { 1.34 + pixels[i] = 255; 1.35 + continue; 1.36 + } 1.37 + 1.38 + if((c = fgetc(fp)) == -1) { 1.39 + fprintf(stderr, "partial read: %s\n", fname); 1.40 + free(pixels); 1.41 + fclose(fp); 1.42 + return 0; 1.43 + } 1.44 + pixels[i] = c; 1.45 } 1.46 fclose(fp); 1.47 1.48 @@ -51,7 +61,7 @@ 1.49 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 1.50 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1.51 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 1.52 - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, xsz, ysz, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels); 1.53 + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, xsz, ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 1.54 free(pixels); 1.55 1.56 return tex;