volmetrics
diff src/main.cc @ 22:4e120dcd55ec
added shaders that just draw
author | Eleni Maria Stea <elene.mst@gmail.com> |
---|---|
date | Thu, 24 Apr 2014 20:47:48 +0300 |
parents | c22866ecb7ae |
children | 930c063ae346 |
line diff
1.1 --- a/src/main.cc Tue Mar 25 00:17:39 2014 +0200 1.2 +++ b/src/main.cc Thu Apr 24 20:47:48 2014 +0300 1.3 @@ -9,6 +9,7 @@ 1.4 #include <vector> 1.5 1.6 #include "mesh.h" 1.7 +#include "sdr.h" 1.8 #include "volume.h" 1.9 1.10 static bool init(void); 1.11 @@ -34,17 +35,21 @@ 1.12 static std::vector<bool> key_state(256); 1.13 1.14 static const char *vol_fname = "data/test1.vol"; 1.15 +static const char *vsdr_path = "data/shaders/transfer.v.glsl"; 1.16 +static const char *fsdr_path = "data/shaders/transfer.f.glsl"; 1.17 1.18 static Volume *vol; 1.19 static Mesh *mesh; 1.20 static float cur_z, thres = 0.5, thres2 = 1.0; 1.21 -static float zeta; 1.22 +static float slice_z; 1.23 1.24 static int use_orig_vol_res = 1; 1.25 static int vol_res[3]; // volume sampling resolution x/y/z 1.26 1.27 static GLUI *ui; 1.28 1.29 +static unsigned int sprog; 1.30 + 1.31 int main(int argc, char **argv) 1.32 { 1.33 glutInit(&argc, argv); 1.34 @@ -80,10 +85,24 @@ 1.35 glEnable(GL_DEPTH_TEST); 1.36 glEnable(GL_NORMALIZE); 1.37 1.38 - glEnable(GL_LIGHTING); //TODO: shaders 1.39 + glEnable(GL_LIGHTING); 1.40 glEnable(GL_LIGHT0); 1.41 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1); 1.42 1.43 + //FIXME shaders setup 1.44 + if(!(sprog = sdr_getprog(vsdr_path, fsdr_path))) 1.45 + { 1.46 + fprintf(stderr, "Failed to create shader program!\n"); 1.47 + return false; 1.48 + } 1.49 + glUseProgram(sprog); 1.50 + float t1 = glGetUniformLocation(sprog, "thres1"); 1.51 + if(t1 != -1) 1.52 + glUniform1f(t1, 0); 1.53 + float t2 = glGetUniformLocation(sprog, "thres2"); 1.54 + glUniform1f(t2, 1); 1.55 + glUseProgram(0); 1.56 + 1.57 vol = new Volume; 1.58 if(!vol->load(vol_fname)) { 1.59 fprintf(stderr, "Failed to load %s", vol_fname); 1.60 @@ -171,7 +190,7 @@ 1.61 1.62 GLUI_Panel *preview_panel = ui->add_panel("volume preview"); 1.63 1.64 - GLUI_Spinner *preview_spin = ui->add_spinner_to_panel(preview_panel, "slice z", GLUI_SPINNER_FLOAT, &zeta, 0); 1.65 + GLUI_Spinner *preview_spin = ui->add_spinner_to_panel(preview_panel, "slice z", GLUI_SPINNER_FLOAT, &slice_z, 0); 1.66 preview_spin->set_float_limits(0, 1); 1.67 1.68 return ui; 1.69 @@ -184,6 +203,8 @@ 1.70 glDisable(GL_LIGHTING); 1.71 glDisable(GL_DEPTH_TEST); 1.72 1.73 + glUseProgram(sprog); 1.74 + 1.75 glMatrixMode(GL_MODELVIEW); 1.76 glPushMatrix(); 1.77 glLoadIdentity(); 1.78 @@ -197,10 +218,10 @@ 1.79 glEnable(GL_TEXTURE_3D); 1.80 glBegin(GL_QUADS); 1.81 glColor3f(1.0, 1.0, 1.0); 1.82 - glTexCoord3f(0, 0, zeta); glVertex3f(-1.0, 1.0, 0.0); 1.83 - glTexCoord3f(0, 1, zeta); glVertex3f(-1.0, 0.5, 0.0); 1.84 - glTexCoord3f(1, 1, zeta); glVertex3f(-0.5, 0.5, 0.0); 1.85 - glTexCoord3f(1, 0, zeta); glVertex3f(-0.5, 1.0, 0.0); 1.86 + glTexCoord3f(0, 0, slice_z); glVertex3f(-1.0, 1.0, 0.0); 1.87 + glTexCoord3f(0, 1, slice_z); glVertex3f(-1.0, 0.5, 0.0); 1.88 + glTexCoord3f(1, 1, slice_z); glVertex3f(-0.5, 0.5, 0.0); 1.89 + glTexCoord3f(1, 0, slice_z); glVertex3f(-0.5, 1.0, 0.0); 1.90 glEnd(); 1.91 glDisable(GL_TEXTURE_3D); 1.92 1.93 @@ -219,6 +240,8 @@ 1.94 glMatrixMode(GL_MODELVIEW); 1.95 glPopMatrix(); 1.96 1.97 + glUseProgram(0); 1.98 + 1.99 glEnable(GL_DEPTH_TEST); 1.100 glEnable(GL_LIGHTING); 1.101 }