X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=blobdiff_plain;f=src%2Fpolytest.c;h=0d5187d868cdb58b5a9a762062341a1410118cca;hp=826b0b0c5a5439a8a2df57f7d65d0ddf4bef53e7;hb=9e546fcbdc870e396abeb6eaacaa7bc4054a61f0;hpb=dce48eb322ddf2a3c3622fc132ece21ba7653da3 diff --git a/src/polytest.c b/src/polytest.c index 826b0b0..0d5187d 100644 --- a/src/polytest.c +++ b/src/polytest.c @@ -6,6 +6,7 @@ #include "demo.h" #include "3dgfx.h" #include "gfxutil.h" +#include "polyfill.h" /* just for struct pimage */ struct mesh { int prim; @@ -23,6 +24,7 @@ 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 int gen_texture(struct pimage *img, int xsz, int ysz); static struct screen scr = { "polytest", @@ -35,6 +37,8 @@ static struct screen scr = { static float theta, phi = 25; static struct mesh cube, torus; +static struct pimage tex; + #define LOWRES_SCALE 10 static uint16_t *lowres_pixels; static int lowres_width, lowres_height; @@ -46,8 +50,17 @@ 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); + /* scale texcoords */ + for(i=0; i 90) phi = 90; @@ -113,7 +130,13 @@ static void draw(void) 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.4, 0.7, 1.0); + g3d_set_texture(tex.width, tex.height, tex.pixels); + draw_mesh(&torus); /*draw_mesh(&cube);*/ @@ -260,6 +283,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; } @@ -370,3 +395,26 @@ static void draw_lowres_raster(void) dptr += fb_width * LOWRES_SCALE - fb_width; } } + +static int gen_texture(struct pimage *img, int xsz, int ysz) +{ + int i, j; + uint16_t *pix; + + if(!(img->pixels = malloc(xsz * ysz * sizeof *pix))) { + return -1; + } + pix = img->pixels; + + for(i=0; iwidth = xsz; + img->height = ysz; + return 0; +}