X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=blobdiff_plain;f=src%2Fpolytest.c;h=1815bb95b17a4769062c56374c2eeda0f0cbdda8;hp=a2985dd99a7c8a4198f187b083fa110cee8d0410;hb=6c5e65928b425dd6a7f5192841e1d4ef9d90789a;hpb=90a1ba8903eed9e3d4b17f4b56cd02ed801dd8b6 diff --git a/src/polytest.c b/src/polytest.c index a2985dd..1815bb9 100644 --- a/src/polytest.c +++ b/src/polytest.c @@ -5,6 +5,9 @@ #include "screen.h" #include "demo.h" #include "3dgfx.h" +#include "gfxutil.h" +#include "polyfill.h" /* just for struct pimage */ +#include "cfgopt.h" struct mesh { int prim; @@ -20,8 +23,9 @@ static void draw(void); 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 int dump_obj(const char *fname, struct mesh *m); static void zsort(struct mesh *m); +static void draw_lowres_raster(void); +static int gen_texture(struct pimage *img, int xsz, int ysz); static struct screen scr = { "polytest", @@ -31,8 +35,16 @@ static struct screen scr = { draw }; +static float cam_theta, cam_phi = 25; +static float cam_dist = 3; static struct mesh cube, torus; +static struct pimage tex; + +#define LOWRES_SCALE 10 +static uint16_t *lowres_pixels; +static int lowres_width, lowres_height; + struct screen *polytest_screen(void) { return &scr; @@ -40,15 +52,34 @@ struct screen *polytest_screen(void) static int init(void) { + int i; + gen_cube(&cube, 1.0); gen_torus(&torus, 1.0, 0.25, 24, 12); - dump_obj("torus.obj", &torus); + /* scale texcoords */ + for(i=0; i 90) cam_phi = 90; + } + if(mouse_bmask & 4) { + cam_dist += dy * 0.5; + + if(cam_dist < 0) cam_dist = 0; + } + } + } + } prev_mx = mouse_x; prev_my = mouse_y; + prev_bmask = mouse_bmask; +} - if(dx || dy) { - theta += dx * 2.0; - phi += dy * 2.0; - - if(phi < -90) phi = -90; - if(phi > 90) phi = 90; - } - /*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_rotate(phi, 1, 0, 0); - g3d_rotate(theta, 0, 1, 0); + g3d_translate(0, 0, -cam_dist); + if(opt.sball) { + g3d_mult_matrix(sball_matrix); + } else { + g3d_rotate(cam_phi, 1, 0, 0); + g3d_rotate(cam_theta, 0, 1, 0); + } + + g3d_light_pos(0, -10, 10, 20); zsort(&torus); + + g3d_mtl_diffuse(0.4, 0.7, 1.0); + g3d_set_texture(tex.width, tex.height, tex.pixels); + 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, -cam_dist); + g3d_rotate(cam_phi, 1, 0, 0); + g3d_rotate(cam_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) @@ -204,6 +296,8 @@ static int gen_torus(struct mesh *mesh, float rad, float ringrad, int usub, int nfaces = usub * vsub; mesh->icount = nfaces * 4; + printf("generating torus with %d faces (%d vertices)\n", nfaces, mesh->vcount); + if(!(mesh->varr = malloc(mesh->vcount * sizeof *mesh->varr))) { return -1; } @@ -249,50 +343,6 @@ static int gen_torus(struct mesh *mesh, float rad, float ringrad, int usub, int return 0; } -static int dump_obj(const char *fname, struct mesh *m) -{ - int i, j, nfaces; - FILE *fp; - struct g3d_vertex *vptr; - int16_t *iptr; - - if(!(fp = fopen(fname, "wb"))) { - return -1; - } - - nfaces = m->icount / m->prim; - printf("dumping obj: %s - %d vertices / %d faces (%d indices)\n", fname, - m->vcount, nfaces, m->icount); - - vptr = m->varr; - for(i=0; ivcount; i++) { - fprintf(fp, "v %f %f %f\n", vptr->x, vptr->y, vptr->z); - ++vptr; - } - vptr = m->varr; - for(i=0; ivcount; i++) { - fprintf(fp, "vn %f %f %f\n", vptr->nx, vptr->ny, vptr->nz); - ++vptr; - } - vptr = m->varr; - for(i=0; ivcount; i++) { - fprintf(fp, "vt %f %f\n", vptr->u, vptr->v); - ++vptr; - } - - iptr = m->iarr; - for(i=0; iicount; i += m->prim) { - fputc('f', fp); - for(j=0; jprim; j++) { - int idx = *iptr++ + 1; - fprintf(fp, " %d/%d/%d", idx, idx, idx); - } - fputc('\n', fp); - } - - fclose(fp); - return 0; -} static struct { struct g3d_vertex *varr; @@ -330,3 +380,54 @@ 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; ipixels = malloc(xsz * ysz * sizeof *pix))) { + return -1; + } + pix = img->pixels; + + for(i=0; iwidth = xsz; + img->height = ysz; + return 0; +}