qvolray

diff src/demo.cc @ 18:3d05c261a2f4

demo metaballs crash & burn
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 11 Apr 2012 06:08:59 +0300
parents
children 4c62be57fc1a
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/demo.cc	Wed Apr 11 06:08:59 2012 +0300
     1.3 @@ -0,0 +1,61 @@
     1.4 +#include <GL/glew.h>
     1.5 +#include "demo.h"
     1.6 +#include "sdr.h"
     1.7 +#include "volray.h"
     1.8 +
     1.9 +#define SZ	128
    1.10 +
    1.11 +static Volume *vol;
    1.12 +static unsigned int sdr_mballs;
    1.13 +static unsigned int fbo;
    1.14 +
    1.15 +bool init_demo()
    1.16 +{
    1.17 +	if(!(sdr_mballs = create_program_load("sdr/demo.v.glsl", "sdr/demo.p.glsl"))) {
    1.18 +		return false;
    1.19 +	}
    1.20 +
    1.21 +	vol = new Volume;
    1.22 +	vol->create(SZ, SZ, SZ);
    1.23 +	volray_setvolume(vol);
    1.24 +
    1.25 +	glGenFramebuffers(1, &fbo);
    1.26 +	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
    1.27 +	glFramebufferTexture3D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_3D,
    1.28 +			vol->get_texture(), 0, 0);
    1.29 +
    1.30 +	unsigned int stat = glCheckFramebufferStatus(GL_FRAMEBUFFER);
    1.31 +	if(stat != GL_FRAMEBUFFER_COMPLETE) {
    1.32 +		printf("incomplete framebuffer: %u\n", stat);
    1.33 +		delete vol;
    1.34 +		return false;
    1.35 +	}
    1.36 +	glBindFramebuffer(GL_FRAMEBUFFER, 0);
    1.37 +
    1.38 +	return true;
    1.39 +}
    1.40 +
    1.41 +void draw_demo()
    1.42 +{
    1.43 +	if(volray_getvolume() != vol) {
    1.44 +		return;
    1.45 +	}
    1.46 +
    1.47 +	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
    1.48 +	bind_program(sdr_mballs);
    1.49 +
    1.50 +	for(int i=0; i<SZ; i++) {
    1.51 +		glFramebufferTexture3D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_3D,
    1.52 +				vol->get_texture(), 0, i);
    1.53 +
    1.54 +		glBegin(GL_QUADS);
    1.55 +		glVertex2f(-1, -1);
    1.56 +		glVertex2f(1, -1);
    1.57 +		glVertex2f(1, 1);
    1.58 +		glVertex2f(-1, 1);
    1.59 +		glEnd();
    1.60 +	}
    1.61 +
    1.62 +	bind_program(0);
    1.63 +	glBindFramebuffer(GL_FRAMEBUFFER, 0);
    1.64 +}