X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fpart_whitted.c;h=6c176b4c41e7099a359d44befd87a0458e1ca528;hb=HEAD;hp=7154abf7ce15fef40bcd34fc61d9336795fbaa42;hpb=6a752049e496c93a61e0130348f71888583d743c;p=demo_prior diff --git a/src/part_whitted.c b/src/part_whitted.c index 7154abf..6c176b4 100644 --- a/src/part_whitted.c +++ b/src/part_whitted.c @@ -1,6 +1,10 @@ #include "opengl.h" #include "demo.h" #include "part.h" +#include "sdr.h" +#include "texture.h" +#include "post.h" +#include "imtk.h" static int init(void); static void destroy(void); @@ -10,10 +14,6 @@ static void draw(long tm); static void mbutton(int bn, int st, int x, int y); static void mmotion(int x, int y); -static float cam_theta, cam_phi, cam_dist = 8; - -static int bnstate[8]; -static int mouse_x, mouse_y; static struct demo_part part = { "whitted", @@ -26,6 +26,18 @@ static struct demo_part part = { mbutton, mmotion }; +static float cam_theta, cam_phi, cam_dist = 6; + +static int bnstate[8]; +static int mouse_x, mouse_y; + +static unsigned int sdr; +static int uloc_aspect; + +static struct texture *dbgtex; +static float dbg_alpha; + + void reg_whitted(void) { add_part(&part); @@ -34,11 +46,19 @@ void reg_whitted(void) static int init(void) { + if(!(sdr = create_program_load("sdr/whitted.v.glsl", "sdr/whitted.p.glsl"))) { + return -1; + } + uloc_aspect = get_uniform_loc(sdr, "aspect"); + + dbgtex = load_texture("data/dbg_whitted.jpg"); + return 0; } static void destroy(void) { + free_texture(dbgtex); } static void start(void) @@ -51,18 +71,66 @@ static void stop(void) static void draw(long tm) { + static float vgn_offset = 0.47; + static float vgn_sharp = 3.1; + + glDisable(GL_DEPTH_TEST); + glMatrixMode(GL_MODELVIEW); glLoadIdentity(); + /* glTranslatef(0, 0, -cam_dist); glRotatef(cam_phi, 1, 0, 0); glRotatef(cam_theta, 0, 1, 0); + */ + glRotatef(-cam_theta, 0, 1, 0); + glRotatef(-cam_phi, 1, 0, 0); + glTranslatef(0, 0, cam_dist); + + glUseProgram(sdr); + glUniform1f(uloc_aspect, win_aspect); + + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2f(-1, -1); + glTexCoord2f(1, 0); + glVertex2f(1, -1); + glTexCoord2f(1, 1); + glVertex2f(1, 1); + glTexCoord2f(0, 1); + glVertex2f(-1, 1); + glEnd(); + + vignette(0.15, 0.05, 0.15, vgn_offset, vgn_sharp); + + if(dbgtex && dbg_alpha > 0.0) { + glUseProgram(0); + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + glScalef(1, -1, 1); + overlay_tex(dbgtex, dbg_alpha); + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + } + + if(dbgui) { + glUseProgram(0); + + imtk_begin(); + imtk_layout_start(10, 20); + imtk_layout_spacing(10); - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); + imtk_layout_dir(IMTK_HORIZONTAL); - glFrontFace(GL_CW); - glutSolidTeapot(1.0); - glFrontFace(GL_CCW); + imtk_label("offset:", IMTK_AUTO, IMTK_AUTO); + vgn_offset = imtk_slider(IMUID, vgn_offset, 0.0, 1.5, IMTK_AUTO, IMTK_AUTO); + imtk_layout_newline(); + + imtk_label("sharpness:", IMTK_AUTO, IMTK_AUTO); + vgn_sharp = imtk_slider(IMUID, vgn_sharp, 0, 10, IMTK_AUTO, IMTK_AUTO); + imtk_layout_newline(); + imtk_end(); + } } static void mbutton(int bn, int st, int x, int y) @@ -70,6 +138,21 @@ static void mbutton(int bn, int st, int x, int y) bnstate[bn] = st; mouse_x = x; mouse_y = y; + + switch(bn) { + case 0: + if(imtk_layout_contains(x, y)) { + imtk_inp_mouse(bn, st); + } + break; + case 3: + dbg_alpha += 0.1; + if(dbg_alpha > 1.0) dbg_alpha = 1.0; + break; + case 4: + dbg_alpha -= 0.1; + if(dbg_alpha < 0.0) dbg_alpha = 0.0; + } } static void mmotion(int x, int y) @@ -81,6 +164,11 @@ static void mmotion(int x, int y) if(!(dx | dy)) return; + if(imtk_layout_contains(x, y)) { + imtk_inp_motion(x, y); + return; + } + if(bnstate[0]) { cam_theta += dx * 0.5; cam_phi += dy * 0.5;