#include "polyfill.h"
#include "imago2.h"
#include "gfxutil.h"
+#include "mesh.h"
static int init(void);
static void destroy(void);
static float cam_theta = -29, cam_phi = 35;
static float cam_dist = 5;
-static struct pimage tex_crate;
+static struct pimage tex_inner, tex_outer;
+static struct g3d_mesh mesh_cube;
struct screen *infcubes_screen(void)
{
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))) {
+ 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);
+
+ if(!(tex_outer.pixels = img_load_pixels("data/steelfrm.jpg", &tex_outer.width,
+ &tex_outer.height, IMG_FMT_RGB24))) {
+ fprintf(stderr, "infcubes: failed to load ornamental texture\n");
+ return -1;
+ }
+ convimg_rgb24_rgb16(tex_outer.pixels, (unsigned char*)tex_outer.pixels, tex_outer.width, tex_outer.height);
- npixels = tex_crate.width * tex_crate.height;
- src = (unsigned char*)tex_crate.pixels;
- dst = tex_crate.pixels;
- for(i=0; i<npixels; i++) {
- int r = *src++;
- int g = *src++;
- int b = *src++;
- *dst++ = PACK_RGB16(r, g, b);
+ if(gen_cube_mesh(&mesh_cube, 1.0f, 3) == -1) {
+ return -1;
}
return 0;
}
static void destroy(void)
{
- img_free_pixels(tex_crate.pixels);
+ img_free_pixels(tex_inner.pixels);
}
static void start(long trans_time)
g3d_enable(G3D_CULL_FACE);
g3d_disable(G3D_LIGHTING);
g3d_enable(G3D_LIGHT0);
-
- g3d_set_texture(tex_crate.width, tex_crate.height, tex_crate.pixels);
}
static void update(void)
memset(fb_pixels, 0, fb_width * fb_height * 2);
- g3d_polygon_mode(G3D_FLAT);
- draw_cube(-6);
-
g3d_polygon_mode(G3D_TEX);
- draw_cube(1);
- swap_buffers(fb_pixels);
-}
+ g3d_push_matrix();
+ g3d_scale(-6, -6, -6);
+ g3d_set_texture(tex_outer.width, tex_outer.height, tex_outer.pixels);
+ draw_mesh(&mesh_cube);
+ g3d_pop_matrix();
-static void draw_cube(float sz)
-{
- float hsz = sz * 0.5f;
- g3d_begin(G3D_QUADS);
- g3d_color3b(255, 0, 0);
- g3d_normal(0, 0, 1);
- g3d_texcoord(0, 0); g3d_vertex(-hsz, -hsz, hsz);
- g3d_texcoord(1, 0); g3d_vertex(hsz, -hsz, hsz);
- g3d_texcoord(1, 1); g3d_vertex(hsz, hsz, hsz);
- g3d_texcoord(0, 1); g3d_vertex(-hsz, hsz, hsz);
- g3d_color3b(0, 255, 0);
- g3d_normal(1, 0, 0);
- g3d_texcoord(0, 0); g3d_vertex(hsz, -hsz, hsz);
- g3d_texcoord(1, 0); g3d_vertex(hsz, -hsz, -hsz);
- g3d_texcoord(1, 1); g3d_vertex(hsz, hsz, -hsz);
- g3d_texcoord(0, 1); g3d_vertex(hsz, hsz, hsz);
- g3d_color3b(0, 0, 255);
- g3d_normal(0, 0, -1);
- g3d_texcoord(0, 0); g3d_vertex(hsz, -hsz, -hsz);
- g3d_texcoord(1, 0); g3d_vertex(-hsz, -hsz, -hsz);
- g3d_texcoord(1, 1); g3d_vertex(-hsz, hsz, -hsz);
- g3d_texcoord(0, 1); g3d_vertex(hsz, hsz, -hsz);
- g3d_color3b(255, 0, 255);
- g3d_normal(-1, 0, 0);
- g3d_texcoord(0, 0); g3d_vertex(-hsz, -hsz, -hsz);
- g3d_texcoord(1, 0); g3d_vertex(-hsz, -hsz, hsz);
- g3d_texcoord(1, 1); g3d_vertex(-hsz, hsz, hsz);
- g3d_texcoord(0, 1); g3d_vertex(-hsz, hsz, -hsz);
- g3d_color3b(255, 255, 0);
- g3d_normal(0, 1, 0);
- g3d_texcoord(0, 0); g3d_vertex(-hsz, hsz, hsz);
- g3d_texcoord(1, 0); g3d_vertex(hsz, hsz, hsz);
- g3d_texcoord(1, 1); g3d_vertex(hsz, hsz, -hsz);
- g3d_texcoord(0, 1); g3d_vertex(-hsz, hsz, -hsz);
- g3d_color3b(0, 255, 255);
- g3d_normal(0, -1, 0);
- g3d_texcoord(0, 0); g3d_vertex(hsz, -hsz, hsz);
- g3d_texcoord(1, 0); g3d_vertex(-hsz, -hsz, hsz);
- g3d_texcoord(1, 1); g3d_vertex(-hsz, -hsz, -hsz);
- g3d_texcoord(0, 1); g3d_vertex(hsz, -hsz, -hsz);
- g3d_end();
+ g3d_set_texture(tex_inner.width, tex_inner.height, tex_inner.pixels);
+ draw_mesh(&mesh_cube);
+
+ swap_buffers(fb_pixels);
}