labyrinth

diff src/texture.c @ 5:c8826e5ebec1

- changed every data loading function to return dummy objects instead of failing - fixed mistake in AndroidManifest.xml
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 01 May 2015 05:58:41 +0300
parents 8ba79034e8a6
children
line diff
     1.1 --- a/src/texture.c	Fri May 01 04:38:43 2015 +0300
     1.2 +++ b/src/texture.c	Fri May 01 05:58:41 2015 +0300
     1.3 @@ -7,6 +7,8 @@
     1.4  #define GL_GENERATE_MIPMAP_SGIS 0x8191
     1.5  #endif
     1.6  
     1.7 +static unsigned int default_texture(void);
     1.8 +
     1.9  unsigned int load_texture(const char *fname)
    1.10  {
    1.11  	unsigned int tex;
    1.12 @@ -14,7 +16,7 @@
    1.13  
    1.14  	if(!(img = load_image(fname))) {
    1.15  		fprintf(stderr, "failed to load image: %s\n", fname);
    1.16 -		return 0;
    1.17 +		return default_texture();
    1.18  	}
    1.19  
    1.20  	glGenTextures(1, &tex);
    1.21 @@ -26,3 +28,36 @@
    1.22  	free_image(img);
    1.23  	return tex;
    1.24  }
    1.25 +
    1.26 +#define DEF_TEX_SZ	64
    1.27 +
    1.28 +static unsigned int default_texture(void)
    1.29 +{
    1.30 +	static unsigned int tex;
    1.31 +	static unsigned char pixels[DEF_TEX_SZ * DEF_TEX_SZ * 3];
    1.32 +
    1.33 +	if(!tex) {
    1.34 +		/* generate it */
    1.35 +		int i, j;
    1.36 +		unsigned char *pptr = pixels;
    1.37 +
    1.38 +		for(i=0; i<DEF_TEX_SZ; i++) {
    1.39 +			for(j=0; j<DEF_TEX_SZ; j++) {
    1.40 +				int c = ((i >> 3) & 1) == ((j >> 3) & 1);
    1.41 +
    1.42 +				*pptr++ = c ? 255 : 64;
    1.43 +				*pptr++ = 100;
    1.44 +				*pptr++ = c ? 64 : 255;
    1.45 +			}
    1.46 +		}
    1.47 +
    1.48 +		glGenTextures(1, &tex);
    1.49 +		glBindTexture(GL_TEXTURE_2D, tex);
    1.50 +		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    1.51 +		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    1.52 +		glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
    1.53 +		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, DEF_TEX_SZ, DEF_TEX_SZ, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
    1.54 +	}
    1.55 +
    1.56 +	return tex;
    1.57 +}