X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=blobdiff_plain;f=src%2Finfcubes.c;h=dd1bd33a2b4ec83ea83b5c790c83471dab9949c6;hp=5fe7df9d8a4016402e1e9c5356281e0ee4c3df63;hb=3398fc6c4188104048f99b650a6cb90beda9b6ed;hpb=9ed338a5e703fc819cede5cb797e82e08046ac17 diff --git a/src/infcubes.c b/src/infcubes.c index 5fe7df9..dd1bd33 100644 --- a/src/infcubes.c +++ b/src/infcubes.c @@ -1,15 +1,22 @@ #include +#include +#include #include #include "demo.h" #include "3dgfx.h" #include "screen.h" #include "cfgopt.h" +#include "polyfill.h" +#include "imago2.h" +#include "gfxutil.h" +#include "mesh.h" static int init(void); static void destroy(void); static void start(long trans_time); static void draw(void); -static void draw_cube(void); +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", @@ -19,31 +26,68 @@ static struct screen scr = { draw }; -static float cam_theta, cam_phi; -static float cam_dist = 5; +static float cam_theta = -29, cam_phi = 35; +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) { + 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); + + if(!(tex_outer.pixels = img_load_pixels("data/refmap1.jpg", &tex_outer.width, + &tex_outer.height, IMG_FMT_RGB24))) { + fprintf(stderr, "infcubes: failed to load outer texture\n"); + return -1; + } + convimg_rgb24_rgb16(tex_outer.pixels, (unsigned char*)tex_outer.pixels, tex_outer.width, tex_outer.height); + /*gen_phong_tex(&tex_outer, PHONG_TEX_SZ, PHONG_TEX_SZ, 5.0f, 50, 50, 50, 255, 255, 255);*/ + + /* + if(gen_cube_mesh(&mesh_cube, 1.0f, 3) == -1) { + return -1; + } + */ + if(load_mesh(&mesh_cube, "data/bevelbox.obj") == -1) { + return -1; + } + if(load_mesh(&mesh_cube2, "data/bevelbox.obj") == -1) { + return -1; + } + apply_mesh_xform(&mesh_cube2, scalemat); + normalize_mesh_normals(&mesh_cube2); return 0; } static void destroy(void) { + img_free_pixels(tex_inner.pixels); } static void start(long trans_time) { g3d_matrix_mode(G3D_PROJECTION); g3d_load_identity(); - g3d_perspective(50.0, 1.3333333, 0.5, 100.0); + g3d_perspective(70.0, 1.3333333, 0.5, 100.0); - g3d_enable(G3D_LIGHTING); + g3d_enable(G3D_CULL_FACE); + g3d_disable(G3D_LIGHTING); g3d_enable(G3D_LIGHT0); } @@ -54,6 +98,7 @@ static void update(void) static void draw(void) { + float t = (float)time_msec / 16.0f; update(); g3d_matrix_mode(G3D_MODELVIEW); @@ -67,43 +112,63 @@ static void draw(void) memset(fb_pixels, 0, fb_width * fb_height * 2); - draw_cube(); + g3d_polygon_mode(G3D_FLAT); + g3d_enable(G3D_TEXTURE_2D); + g3d_enable(G3D_TEXTURE_GEN); + + g3d_push_matrix(); + g3d_rotate(t, 1, 0, 0); + g3d_rotate(t, 0, 1, 0); + g3d_set_texture(tex_outer.width, tex_outer.height, tex_outer.pixels); + draw_mesh(&mesh_cube2); + g3d_pop_matrix(); + + g3d_set_texture(tex_inner.width, tex_inner.height, tex_inner.pixels); + draw_mesh(&mesh_cube); + g3d_disable(G3D_TEXTURE_GEN); swap_buffers(fb_pixels); } -static void draw_cube(void) +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) { - g3d_begin(G3D_QUADS); - g3d_normal(0, 0, 1); - g3d_vertex(-1, -1, 1); - g3d_vertex(1, -1, 1); - g3d_vertex(1, 1, 1); - g3d_vertex(-1, 1, 1); - g3d_normal(1, 0, 0); - g3d_vertex(1, -1, 1); - g3d_vertex(1, -1, -1); - g3d_vertex(1, 1, -1); - g3d_vertex(1, 1, 1); - g3d_normal(0, 0, -1); - g3d_vertex(1, -1, -1); - g3d_vertex(-1, -1, -1); - g3d_vertex(-1, 1, -1); - g3d_vertex(1, 1, -1); - g3d_normal(-1, 0, 0); - g3d_vertex(-1, -1, -1); - g3d_vertex(-1, -1, 1); - g3d_vertex(-1, 1, 1); - g3d_vertex(-1, 1, -1); - g3d_normal(0, 1, 0); - g3d_vertex(-1, 1, 1); - g3d_vertex(1, 1, 1); - g3d_vertex(1, 1, -1); - g3d_vertex(-1, 1, -1); - g3d_normal(0, -1, 0); - g3d_vertex(1, -1, 1); - g3d_vertex(-1, -1, 1); - g3d_vertex(-1, -1, -1); - g3d_vertex(1, -1, -1); - g3d_end(); + int i, j; + float u, v, du, dv; + uint16_t *pix; + + if(!(img->pixels = 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; }