qvolray

view src/demo.cc @ 21:4c62be57fc1a

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 11 Apr 2012 16:59:45 +0300
parents 3d05c261a2f4
children c27ce79632db
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 glPushAttrib(GL_VIEWPORT_BIT);
45 glViewport(0, 0, SZ, SZ);
47 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
48 bind_program(sdr_mballs);
50 for(int i=0; i<SZ; i++) {
51 glFramebufferTexture3D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_3D,
52 vol->get_texture(), 0, i);
54 float z = (float)i / (float)SZ;
56 glBegin(GL_QUADS);
57 glTexCoord3f(0, 0, z);
58 glVertex2f(-1, -1);
59 glTexCoord3f(1, 0, z);
60 glVertex2f(1, -1);
61 glTexCoord3f(1, 1, z);
62 glVertex2f(1, 1);
63 glTexCoord3f(0, 1, z);
64 glVertex2f(-1, 1);
65 glEnd();
66 }
68 bind_program(0);
69 glBindFramebuffer(GL_FRAMEBUFFER, 0);
71 glPopAttrib();
72 }