X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fpolytest.c;h=58fdb41578185727f67cc9b7677414a9bbeddb59;hb=25669bf7362645d1c0fee9d7cb07f4a6b0b34903;hp=0217916fe6c8233f779ba70b944649bce6f8c8fa;hpb=c9f6f3f5f55af44352b94b55ecca0d7098bfab5e;p=dosdemo diff --git a/src/polytest.c b/src/polytest.c index 0217916..58fdb41 100644 --- a/src/polytest.c +++ b/src/polytest.c @@ -5,6 +5,7 @@ #include "screen.h" #include "demo.h" #include "3dgfx.h" +#include "gfxutil.h" struct mesh { int prim; @@ -21,6 +22,7 @@ static void draw_mesh(struct mesh *mesh); static int gen_cube(struct mesh *mesh, float sz); static int gen_torus(struct mesh *mesh, float rad, float ringrad, int usub, int vsub); static void zsort(struct mesh *m); +static void draw_lowres_raster(void); static struct screen scr = { "polytest", @@ -30,8 +32,13 @@ static struct screen scr = { draw }; +static float theta, phi = 25; static struct mesh cube, torus; +#define LOWRES_SCALE 10 +static uint16_t *lowres_pixels; +static int lowres_width, lowres_height; + struct screen *polytest_screen(void) { return &scr; @@ -41,11 +48,20 @@ static int init(void) { gen_cube(&cube, 1.0); gen_torus(&torus, 1.0, 0.25, 24, 12); + +#ifdef DEBUG_POLYFILL + lowres_width = fb_width / LOWRES_SCALE; + lowres_height = fb_height / LOWRES_SCALE; + lowres_pixels = malloc(lowres_width * lowres_height * 2); + scr.draw = draw_debug; +#endif + return 0; } static void destroy(void) { + free(lowres_pixels); free(cube.varr); free(torus.varr); free(torus.iarr); @@ -58,38 +74,84 @@ static void start(long trans_time) g3d_perspective(50.0, 1.3333333, 0.5, 100.0); g3d_enable(G3D_CULL_FACE); + g3d_enable(G3D_LIGHTING); + g3d_enable(G3D_LIGHT0); } -static void draw(void) +static void update(void) { static int prev_mx, prev_my; - static float theta, phi = 25; + static unsigned int prev_bmask; - int dx = mouse_x - prev_mx; - int dy = mouse_y - prev_my; - prev_mx = mouse_x; - prev_my = mouse_y; + if(mouse_bmask) { + if((mouse_bmask ^ prev_bmask) == 0) { + int dx = mouse_x - prev_mx; + int dy = mouse_y - prev_my; - if(dx || dy) { - theta += dx * 2.0; - phi += dy * 2.0; + if(dx || dy) { + theta += dx * 2.0; + phi += dy * 2.0; - if(phi < -90) phi = -90; - if(phi > 90) phi = 90; + if(phi < -90) phi = -90; + if(phi > 90) phi = 90; + } + } } + prev_mx = mouse_x; + prev_my = mouse_y; + prev_bmask = mouse_bmask; +} - /*float angle = (float)time_msec / 50.0;*/ + +static void draw(void) +{ + update(); memset(fb_pixels, 0, fb_width * fb_height * 2); g3d_matrix_mode(G3D_MODELVIEW); g3d_load_identity(); - g3d_translate(0, 0, -5); + g3d_translate(0, 0, -3); g3d_rotate(phi, 1, 0, 0); g3d_rotate(theta, 0, 1, 0); + g3d_light_pos(0, -10, 10, 20); + zsort(&torus); + + g3d_mtl_diffuse(0.3, 0.6, 1.0); draw_mesh(&torus); + + /*draw_mesh(&cube);*/ + swap_buffers(fb_pixels); +} + +static void draw_debug(void) +{ + update(); + + memset(lowres_pixels, 0, lowres_width * lowres_height * 2); + + g3d_matrix_mode(G3D_MODELVIEW); + g3d_load_identity(); + g3d_translate(0, 0, -3); + g3d_rotate(phi, 1, 0, 0); + g3d_rotate(theta, 0, 1, 0); + + g3d_framebuffer(lowres_width, lowres_height, lowres_pixels); + /*zsort(&torus);*/ + draw_mesh(&cube); + + draw_lowres_raster(); + + + g3d_framebuffer(fb_width, fb_height, fb_pixels); + + g3d_polygon_mode(G3D_WIRE); + draw_mesh(&cube); + g3d_polygon_mode(G3D_FLAT); + + swap_buffers(fb_pixels); } static void draw_mesh(struct mesh *mesh) @@ -286,3 +348,31 @@ static void zsort(struct mesh *m) qsort(m->iarr, nfaces, m->prim * sizeof *m->iarr, zsort_cmp); } + +static void draw_huge_pixel(uint16_t *dest, int dest_width, uint16_t color) +{ + int i, j; + uint16_t grid_color = PACK_RGB16(127, 127, 127); + + for(i=0; i