intravenous
diff src/vein.cc @ 4:c6a6a64df6de
normalmap
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 22 Apr 2012 05:20:03 +0300 |
parents | 94d4c60af435 |
children | aab0d8ea21cd |
line diff
1.1 --- a/src/vein.cc Sun Apr 22 03:35:18 2012 +0300 1.2 +++ b/src/vein.cc Sun Apr 22 05:20:03 2012 +0300 1.3 @@ -7,20 +7,26 @@ 1.4 #include "vein.h" 1.5 #include "geom.h" 1.6 #include "sdr.h" 1.7 +#include "tex.h" 1.8 1.9 Vein::Vein() 1.10 { 1.11 gen_dist = 16.0; 1.12 - subdiv = 16; 1.13 - ring_subdiv = 16; 1.14 - rad = 1.0; 1.15 + subdiv = 32; 1.16 + ring_subdiv = 24; 1.17 + rad = 2.0; 1.18 1.19 idxbuf = 0; 1.20 + 1.21 + sdr = tex_norm = 0; 1.22 } 1.23 1.24 Vein::~Vein() 1.25 { 1.26 delete [] idxbuf; 1.27 + 1.28 + free_texture(tex_norm); 1.29 + free_program(sdr); 1.30 } 1.31 1.32 Vector3 Vein::calc_center(const Vector3 &ppos) const 1.33 @@ -66,6 +72,11 @@ 1.34 if((attr_tang_loc = get_attrib_loc(sdr, "attr_tang")) == -1) { 1.35 fprintf(stderr, "can't find tangent attribute!\n"); 1.36 } 1.37 + set_uniform_int(sdr, "tex_norm", 0); 1.38 + 1.39 + if(!(tex_norm = load_texture("data/normal1.png"))) { 1.40 + return false; 1.41 + } 1.42 return true; 1.43 } 1.44 1.45 @@ -93,7 +104,7 @@ 1.46 Matrix3x3 vrot{right, up, dir}; 1.47 vrot.transpose(); 1.48 1.49 - float theta = 0.0, dtheta = 2.0 * M_PI / ring_subdiv; 1.50 + float theta = 0.0, dtheta = 2.0 * M_PI / (ring_subdiv - 1); 1.51 for(int j=0; j<ring_subdiv; j++) { 1.52 Vector3 vec = Vector3{-cos(theta) * rad, sin(theta) * rad, 0.0}; 1.53 vec.transform(vrot); 1.54 @@ -102,7 +113,7 @@ 1.55 vptr->pos = vec; 1.56 vptr->norm = cent - vec; 1.57 vptr->tang = dir; 1.58 - vptr->tc = Vector2(); // TODO 1.59 + vptr->tc = Vector2(start_z + gen_dist * i / nslices, theta / (2.0 * M_PI)); 1.60 vptr++; 1.61 1.62 theta += dtheta; 1.63 @@ -117,7 +128,15 @@ 1.64 } 1.65 1.66 // awesome, now draw it 1.67 + glMatrixMode(GL_TEXTURE); 1.68 + glPushMatrix(); 1.69 + glScalef(0.125, 1.0, 1.0); 1.70 + 1.71 + bind_texture(tex_norm); 1.72 bind_program(sdr); 1.73 draw_mesh(GL_QUADS, nfaces * 4, vbuf, idxbuf, attr_tang_loc); 1.74 bind_program(0); 1.75 + bind_texture(0); 1.76 + 1.77 + glPopMatrix(); 1.78 }