X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fpart_whitted.c;h=eb0fe5b01bac803c8f28b27b83f143e1b3b99952;hb=5eefe7b94c8d6c6caa2c10e3835ab0831a3c42a1;hp=7154abf7ce15fef40bcd34fc61d9336795fbaa42;hpb=6a752049e496c93a61e0130348f71888583d743c;p=demo_prior diff --git a/src/part_whitted.c b/src/part_whitted.c index 7154abf..eb0fe5b 100644 --- a/src/part_whitted.c +++ b/src/part_whitted.c @@ -1,6 +1,9 @@ #include "opengl.h" #include "demo.h" #include "part.h" +#include "sdr.h" +#include "texture.h" +#include "post.h" static int init(void); static void destroy(void); @@ -10,10 +13,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 +25,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 +45,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 +70,44 @@ static void stop(void) static void draw(long tm) { + 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); - - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - - glFrontFace(GL_CW); - glutSolidTeapot(1.0); - glFrontFace(GL_CCW); + */ + glRotatef(-cam_theta, 0, 1, 0); + glRotatef(-cam_phi, 1, 0, 0); + glTranslatef(0, 0, cam_dist); + + glBindFramebuffer(GL_FRAMEBUFFER, post_fbo[0]); + glClear(GL_COLOR_BUFFER_BIT); + + 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(); + + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glUseProgram(post_sdr[POST_OLDFIG]); + overlay_tex(post_fbtex, 1.0); + + if(dbgtex) { + glUseProgram(0); + overlay_tex(dbgtex, dbg_alpha); + } } static void mbutton(int bn, int st, int x, int y) @@ -70,6 +115,16 @@ static void mbutton(int bn, int st, int x, int y) bnstate[bn] = st; mouse_x = x; mouse_y = y; + + switch(bn) { + 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)