bloboland

diff src/renderer.cc @ 4:9021a906c5d3

lots of stuff
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 18 Dec 2012 06:13:09 +0200
parents a39c301cdcce
children 2f4406cc341e
line diff
     1.1 --- a/src/renderer.cc	Sun Dec 16 14:24:16 2012 +0200
     1.2 +++ b/src/renderer.cc	Tue Dec 18 06:13:09 2012 +0200
     1.3 @@ -4,6 +4,7 @@
     1.4  
     1.5  Renderer::Renderer()
     1.6  {
     1.7 +	blobtex = 0;
     1.8  	leveltex = 0;
     1.9  	sdrprog = 0;
    1.10  
    1.11 @@ -29,6 +30,10 @@
    1.12  	leveltex = new Texture3D;
    1.13  	leveltex->create(vol->get_size(0), vol->get_size(1), vol->get_size(2));
    1.14  
    1.15 +	blobtex = new Texture1D;
    1.16 +	blobtex->create(level->blobs.size());
    1.17 +	blobtex->set_filtering(GL_NEAREST);
    1.18 +
    1.19  	this->level = level;
    1.20  
    1.21  	return true;
    1.22 @@ -57,11 +62,19 @@
    1.23  void Renderer::render() const
    1.24  {
    1.25  	leveltex->update((float*)level->terrain->get_data_ptr());
    1.26 -	bind_texture(leveltex);
    1.27 +	((Renderer*)this)->update_blobtex();
    1.28  
    1.29 +	bind_texture(leveltex, 0);
    1.30 +	bind_texture(blobtex, 1);
    1.31 +
    1.32 +	set_uniform_float3(sdrprog, "worldsize", level->world_size.x, level->world_size.y,
    1.33 +			level->world_size.z);
    1.34  	set_uniform_float3(sdrprog, "volsize", level->terrain->get_size(0),
    1.35  			level->terrain->get_size(1), level->terrain->get_size(2));
    1.36  	set_uniform_float4(sdrprog, "camprop", fov, aspect, 0, 0);
    1.37 +
    1.38 +	set_uniform_int(sdrprog, "voltex", 0);
    1.39 +	set_uniform_int(sdrprog, "blobtex", 1);
    1.40  	bind_program(sdrprog);
    1.41  
    1.42  	glBegin(GL_QUADS);
    1.43 @@ -76,7 +89,8 @@
    1.44  	glEnd();
    1.45  
    1.46  	bind_program(0);
    1.47 -	bind_texture(0);
    1.48 +	bind_texture(0, 1);
    1.49 +	bind_texture(0, 0);
    1.50  
    1.51  	/*glEnable(GL_COLOR_MATERIAL);
    1.52  	glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
    1.53 @@ -147,3 +161,20 @@
    1.54  	glVertex3f(pos.x - sz, pos.y - sz, pos.z + sz);
    1.55  
    1.56  }
    1.57 +
    1.58 +void Renderer::update_blobtex()
    1.59 +{
    1.60 +	int nblobs = (int)level->blobs.size();
    1.61 +
    1.62 +	float *data = (float*)alloca(nblobs * 4 * sizeof *data);
    1.63 +	float *dptr = data;
    1.64 +
    1.65 +	for(int i=0; i<nblobs; i++) {
    1.66 +		*dptr++ = level->blobs[i].pos.x;
    1.67 +		*dptr++ = level->blobs[i].pos.y;
    1.68 +		*dptr++ = level->blobs[i].pos.z;
    1.69 +		*dptr++ = 1.0;
    1.70 +	}
    1.71 +
    1.72 +	blobtex->update(data);
    1.73 +}