# HG changeset patch # User John Tsiombikas # Date 1335061203 -10800 # Node ID c6a6a64df6dea4e5d2493b63547b64d922c27326 # Parent 94d4c60af43552520e323654a7bc95bdf2ac1c9c normalmap diff -r 94d4c60af435 -r c6a6a64df6de sdr/vein.p.glsl --- a/sdr/vein.p.glsl Sun Apr 22 03:35:18 2012 +0300 +++ b/sdr/vein.p.glsl Sun Apr 22 05:20:03 2012 +0300 @@ -1,15 +1,18 @@ +uniform sampler2D tex_norm; + varying vec3 vpos, vnorm; varying vec3 ldir, vdir; void main() { - vec3 n = normalize(vnorm); - vec3 l = normalize(ldir); + vec3 tnorm = texture2D(tex_norm, gl_TexCoord[0].st).xyz * 2.0 - 1.0; + vec3 n = normalize(tnorm); vec3 v = normalize(vdir); + vec3 l = v;//normalize(ldir); vec3 h = normalize(l + v); - vec3 diff = vec3(0.8, 0.25, 0.2) * max(dot(l, n), 0.0); - vec3 spec = vec3(0.6, 0.4, 0.32) * pow(max(dot(h, n), 0.0), 60.0); + vec3 diff = vec3(0.8, 0.25, 0.2) * (1.0 - max(dot(l, n), 0.0)); + vec3 spec = 0.5 * vec3(0.9, 0.4, 0.3) * pow(max(dot(h, n), 0.0), 10.0); gl_FragColor = vec4(diff + spec, 1.0); } diff -r 94d4c60af435 -r c6a6a64df6de sdr/vein.v.glsl --- a/sdr/vein.v.glsl Sun Apr 22 03:35:18 2012 +0300 +++ b/sdr/vein.v.glsl Sun Apr 22 05:20:03 2012 +0300 @@ -22,5 +22,5 @@ vdir = tbn_mat * -vpos; vnorm = n; - gl_TexCoord[0] = gl_MultiTexCoord0; + gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; } diff -r 94d4c60af435 -r c6a6a64df6de src/cockpit.cc --- a/src/cockpit.cc Sun Apr 22 03:35:18 2012 +0300 +++ b/src/cockpit.cc Sun Apr 22 05:20:03 2012 +0300 @@ -2,6 +2,9 @@ #include "cockpit.h" #include "tex.h" +#define TEX_ASPECT (16.0 / 9.0) +extern int win_xsz, win_ysz; + static unsigned int tex; bool cockpit_init() @@ -19,6 +22,9 @@ void cockpit_draw() { + float view_aspect = (float)win_xsz / (float)win_ysz; + float aspect = TEX_ASPECT / view_aspect; + glPushAttrib(GL_ENABLE_BIT); glDisable(GL_LIGHTING); @@ -36,10 +42,10 @@ glBegin(GL_QUADS); glColor3f(1, 1, 1); - glTexCoord2f(0, 1); glVertex2f(-1, -1); - glTexCoord2f(1, 1); glVertex2f(1, -1); - glTexCoord2f(1, 0); glVertex2f(1, 1); - glTexCoord2f(0, 0); glVertex2f(-1, 1); + glTexCoord2f(0, 1); glVertex2f(-aspect, -1); + glTexCoord2f(1, 1); glVertex2f(aspect, -1); + glTexCoord2f(1, 0); glVertex2f(aspect, 1); + glTexCoord2f(0, 0); glVertex2f(-aspect, 1); glEnd(); glPopMatrix(); diff -r 94d4c60af435 -r c6a6a64df6de src/game.cc --- a/src/game.cc Sun Apr 22 03:35:18 2012 +0300 +++ b/src/game.cc Sun Apr 22 05:20:03 2012 +0300 @@ -11,6 +11,7 @@ static int keystate[256]; static int dbg_inside = false; +static bool ignore_next_motion; static OrbitCamera dbgcam; @@ -113,6 +114,9 @@ if(dbg_inside) { glutPassiveMotionFunc(game_input_mmotion); glutSetCursor(GLUT_CURSOR_NONE); + + ignore_next_motion = true; + glutWarpPointer(win_xsz / 2, win_ysz / 2); } else { glutPassiveMotionFunc(0); glutSetCursor(GLUT_CURSOR_INHERIT); @@ -143,21 +147,20 @@ void game_input_mmotion(int x, int y) { - static bool ignore_next; int dx = x - prev_x; int dy = y - prev_y; prev_x = x; prev_y = y; - if(ignore_next) { - ignore_next = false; + if(ignore_next_motion) { + ignore_next_motion = false; return; } if(dbg_inside) { ship.turn((float)-dx / win_xsz, (float)-dy / win_ysz); - ignore_next = true; + ignore_next_motion = true; glutWarpPointer(win_xsz / 2, win_ysz / 2); } else { if(bnstate[0]) { diff -r 94d4c60af435 -r c6a6a64df6de src/vein.cc --- a/src/vein.cc Sun Apr 22 03:35:18 2012 +0300 +++ b/src/vein.cc Sun Apr 22 05:20:03 2012 +0300 @@ -7,20 +7,26 @@ #include "vein.h" #include "geom.h" #include "sdr.h" +#include "tex.h" Vein::Vein() { gen_dist = 16.0; - subdiv = 16; - ring_subdiv = 16; - rad = 1.0; + subdiv = 32; + ring_subdiv = 24; + rad = 2.0; idxbuf = 0; + + sdr = tex_norm = 0; } Vein::~Vein() { delete [] idxbuf; + + free_texture(tex_norm); + free_program(sdr); } Vector3 Vein::calc_center(const Vector3 &ppos) const @@ -66,6 +72,11 @@ if((attr_tang_loc = get_attrib_loc(sdr, "attr_tang")) == -1) { fprintf(stderr, "can't find tangent attribute!\n"); } + set_uniform_int(sdr, "tex_norm", 0); + + if(!(tex_norm = load_texture("data/normal1.png"))) { + return false; + } return true; } @@ -93,7 +104,7 @@ Matrix3x3 vrot{right, up, dir}; vrot.transpose(); - float theta = 0.0, dtheta = 2.0 * M_PI / ring_subdiv; + float theta = 0.0, dtheta = 2.0 * M_PI / (ring_subdiv - 1); for(int j=0; jpos = vec; vptr->norm = cent - vec; vptr->tang = dir; - vptr->tc = Vector2(); // TODO + vptr->tc = Vector2(start_z + gen_dist * i / nslices, theta / (2.0 * M_PI)); vptr++; theta += dtheta; @@ -117,7 +128,15 @@ } // awesome, now draw it + glMatrixMode(GL_TEXTURE); + glPushMatrix(); + glScalef(0.125, 1.0, 1.0); + + bind_texture(tex_norm); bind_program(sdr); draw_mesh(GL_QUADS, nfaces * 4, vbuf, idxbuf, attr_tang_loc); bind_program(0); + bind_texture(0); + + glPopMatrix(); } diff -r 94d4c60af435 -r c6a6a64df6de src/vein.h --- a/src/vein.h Sun Apr 22 03:35:18 2012 +0300 +++ b/src/vein.h Sun Apr 22 05:20:03 2012 +0300 @@ -13,6 +13,8 @@ unsigned int sdr; int attr_tang_loc; + unsigned int tex_norm; + Vector3 calc_center(const Vector3 &ppos) const; Vector3 calc_dir(const Vector3 &ppos) const;