qvolray

view src/demo.cc @ 24:c27ce79632db

builds on osx with -spec unsupported/macx-clang added a configure script to handle that qmake invocation
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 14 Apr 2012 00:54:11 +0300
parents 4c62be57fc1a
children 70b937008134
line source
1 #include <assert.h>
2 #include <GL/glew.h>
3 #include "demo.h"
4 #include "sdr.h"
5 #include "volray.h"
7 #define SZ 128
9 static Volume *vol;
10 static unsigned int sdr_mballs;
11 static unsigned int fbo;
13 bool init_demo()
14 {
15 if(!(sdr_mballs = create_program_load("sdr/demo.v.glsl", "sdr/demo.p.glsl"))) {
16 return false;
17 }
19 vol = new Volume;
20 vol->create(SZ, SZ, SZ);
21 volray_setvolume(vol);
23 assert(glGenFramebuffersEXT);
24 assert(glBindFramebufferEXT);
25 assert(glFramebufferTexture3DEXT);
26 assert(glCheckFramebufferStatusEXT);
28 glGenFramebuffersEXT(1, &fbo);
29 glBindFramebufferEXT(GL_FRAMEBUFFER, fbo);
30 glFramebufferTexture3DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_3D,
31 vol->get_texture(), 0, 0);
33 unsigned int stat = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
34 if(stat != GL_FRAMEBUFFER_COMPLETE) {
35 printf("incomplete framebuffer: %u\n", stat);
36 delete vol;
37 return false;
38 }
39 glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
41 return true;
42 }
44 void draw_demo()
45 {
46 if(volray_getvolume() != vol) {
47 return;
48 }
50 glPushAttrib(GL_VIEWPORT_BIT);
51 glViewport(0, 0, SZ, SZ);
53 glBindFramebufferEXT(GL_FRAMEBUFFER, fbo);
54 bind_program(sdr_mballs);
56 for(int i=0; i<SZ; i++) {
57 glFramebufferTexture3DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_3D,
58 vol->get_texture(), 0, i);
60 float z = (float)i / (float)SZ;
62 glBegin(GL_QUADS);
63 glTexCoord3f(0, 0, z);
64 glVertex2f(-1, -1);
65 glTexCoord3f(1, 0, z);
66 glVertex2f(1, -1);
67 glTexCoord3f(1, 1, z);
68 glVertex2f(1, 1);
69 glTexCoord3f(0, 1, z);
70 glVertex2f(-1, 1);
71 glEnd();
72 }
74 bind_program(0);
75 glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
77 glPopAttrib();
78 }