X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=blobdiff_plain;f=src%2Finfcubes.c;h=dd1bd33a2b4ec83ea83b5c790c83471dab9949c6;hp=3df25fe834713727cb18687deb5d992a5913cc75;hb=5f36e95f19ad8d7a5a1dd546ffeb54ce95d51749;hpb=a1ede8e271fee1b4d029752603096db2be780e67 diff --git a/src/infcubes.c b/src/infcubes.c index 3df25fe..dd1bd33 100644 --- a/src/infcubes.c +++ b/src/infcubes.c @@ -1,4 +1,5 @@ #include +#include #include #include #include "demo.h" @@ -14,7 +15,8 @@ static int init(void); static void destroy(void); static void start(long trans_time); static void draw(void); -static void draw_cube(float sz); +static int gen_phong_tex(struct pimage *img, int xsz, int ysz, float sexp, + float offx, float offy, int dr, int dg, int db, int sr, int sg, int sb); static struct screen scr = { "infcubes", @@ -25,60 +27,68 @@ static struct screen scr = { }; static float cam_theta = -29, cam_phi = 35; -static float cam_dist = 5; -static struct pimage tex_crate; -static struct g3d_mesh mesh_cube; +static float cam_dist = 6; +static struct pimage tex_inner, tex_outer; +static struct g3d_mesh mesh_cube, mesh_cube2; struct screen *infcubes_screen(void) { return &scr; } +#define PHONG_TEX_SZ 128 static int init(void) { - int i, npixels; - unsigned char *src; - uint16_t *dst; - - if(!(tex_crate.pixels = img_load_pixels("data/crate.jpg", &tex_crate.width, - &tex_crate.height, IMG_FMT_RGB24))) { + static const float scalemat[16] = {-6, 0, 0, 0, 0, -6, 0, 0, 0, 0, -6, 0, 0, 0, 0, 1}; + /* + if(!(tex_inner.pixels = img_load_pixels("data/crate.jpg", &tex_inner.width, + &tex_inner.height, IMG_FMT_RGB24))) { fprintf(stderr, "infcubes: failed to load crate texture\n"); return -1; } + convimg_rgb24_rgb16(tex_inner.pixels, (unsigned char*)tex_inner.pixels, tex_inner.width, tex_inner.height); + */ + gen_phong_tex(&tex_inner, PHONG_TEX_SZ, PHONG_TEX_SZ, 5.0f, 0, 0, 10, 50, 92, 192, 192, 192); - npixels = tex_crate.width * tex_crate.height; - src = (unsigned char*)tex_crate.pixels; - dst = tex_crate.pixels; - for(i=0; ipixels = malloc(xsz * ysz * sizeof *pix))) { + return -1; + } + pix = img->pixels; + + du = 2.0f / (float)(xsz - 1); + dv = 2.0f / (float)(ysz - 1); + + v = -1.0f - offy; + for(i=0; i 255) r = 255; + if(g > 255) g = 255; + if(b > 255) b = 255; + + *pix++ = PACK_RGB16(r, g, b); + + u += du; + } + v += dv; + } + + img->width = xsz; + img->height = ysz; + return 0; }