dungeon_crawler

diff prototype/src/colgrade.cc @ 75:b05ab29cd17d

color grading done
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 22 Oct 2012 03:55:00 +0300
parents 5981917093ff
children
line diff
     1.1 --- a/prototype/src/colgrade.cc	Sun Oct 21 15:56:47 2012 +0300
     1.2 +++ b/prototype/src/colgrade.cc	Mon Oct 22 03:55:00 2012 +0300
     1.3 @@ -117,7 +117,28 @@
     1.4  
     1.5  bool GradePalette::load_shot(const char *fname)
     1.6  {
     1.7 -	return false;	// TODO
     1.8 +	int xsz, ysz;
     1.9 +	unsigned char *img = (unsigned char*)img_load_pixels(fname, &xsz, &ysz, IMG_FMT_RGB24);
    1.10 +	if(!img) {
    1.11 +		fprintf(stderr, "failed to open image: %s\n", fname);
    1.12 +		return false;
    1.13 +	}
    1.14 +
    1.15 +	int nslices = size;
    1.16 +	int slice_sz = size * size * 3;
    1.17 +	unsigned char *pal = img + xsz * (ysz - nslices) * 3;
    1.18 +
    1.19 +	for(int i=0; i<nslices; i++) {
    1.20 +		memcpy(palette + i * slice_sz, pal, slice_sz);
    1.21 +		pal += xsz * 3;
    1.22 +	}
    1.23 +	img_free_pixels(img);
    1.24 +
    1.25 +	glBindTexture(GL_TEXTURE_3D, tex);
    1.26 +	glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, size, size, size, 0, GL_RGB,
    1.27 +			GL_UNSIGNED_BYTE, palette);
    1.28 +
    1.29 +	return true;
    1.30  }
    1.31  
    1.32  unsigned int GradePalette::get_texture() const