qvolray

view 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 source
1 #include <GL/glew.h>
2 #include "demo.h"
3 #include "sdr.h"
4 #include "volray.h"
6 #define SZ 128
8 static Volume *vol;
9 static unsigned int sdr_mballs;
10 static unsigned int fbo;
12 bool init_demo()
13 {
14 if(!(sdr_mballs = create_program_load("sdr/demo.v.glsl", "sdr/demo.p.glsl"))) {
15 return false;
16 }
18 vol = new Volume;
19 vol->create(SZ, SZ, SZ);
20 volray_setvolume(vol);
22 glGenFramebuffers(1, &fbo);
23 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
24 glFramebufferTexture3D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_3D,
25 vol->get_texture(), 0, 0);
27 unsigned int stat = glCheckFramebufferStatus(GL_FRAMEBUFFER);
28 if(stat != GL_FRAMEBUFFER_COMPLETE) {
29 printf("incomplete framebuffer: %u\n", stat);
30 delete vol;
31 return false;
32 }
33 glBindFramebuffer(GL_FRAMEBUFFER, 0);
35 return true;
36 }
38 void draw_demo()
39 {
40 if(volray_getvolume() != vol) {
41 return;
42 }
44 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
45 bind_program(sdr_mballs);
47 for(int i=0; i<SZ; i++) {
48 glFramebufferTexture3D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_3D,
49 vol->get_texture(), 0, i);
51 glBegin(GL_QUADS);
52 glVertex2f(-1, -1);
53 glVertex2f(1, -1);
54 glVertex2f(1, 1);
55 glVertex2f(-1, 1);
56 glEnd();
57 }
59 bind_program(0);
60 glBindFramebuffer(GL_FRAMEBUFFER, 0);
61 }