13 static int init(void);
14 static void destroy(void);
15 static void start(long trans_time);
16 static void draw(void);
17 static void draw_cube(float sz);
19 static struct screen scr = {
27 static float cam_theta = -29, cam_phi = 35;
28 static float cam_dist = 5;
29 static struct pimage tex_inner, tex_outer;
30 static struct g3d_mesh mesh_cube;
32 struct screen *infcubes_screen(void)
40 if(!(tex_inner.pixels = img_load_pixels("data/crate.jpg", &tex_inner.width,
41 &tex_inner.height, IMG_FMT_RGB24))) {
42 fprintf(stderr, "infcubes: failed to load crate texture\n");
45 convimg_rgb24_rgb16(tex_inner.pixels, (unsigned char*)tex_inner.pixels, tex_inner.width, tex_inner.height);
47 if(!(tex_outer.pixels = img_load_pixels("data/steelfrm.jpg", &tex_outer.width,
48 &tex_outer.height, IMG_FMT_RGB24))) {
49 fprintf(stderr, "infcubes: failed to load ornamental texture\n");
52 convimg_rgb24_rgb16(tex_outer.pixels, (unsigned char*)tex_outer.pixels, tex_outer.width, tex_outer.height);
55 if(gen_cube_mesh(&mesh_cube, 1.0f, 3) == -1) {
59 if(load_mesh(&mesh_cube, "data/bevelbox.obj") == -1) {
65 static void destroy(void)
67 img_free_pixels(tex_inner.pixels);
70 static void start(long trans_time)
72 g3d_matrix_mode(G3D_PROJECTION);
74 g3d_perspective(50.0, 1.3333333, 0.5, 100.0);
76 g3d_enable(G3D_CULL_FACE);
77 g3d_disable(G3D_LIGHTING);
78 g3d_enable(G3D_LIGHT0);
81 static void update(void)
83 mouse_orbit_update(&cam_theta, &cam_phi, &cam_dist);
86 static void draw(void)
90 g3d_matrix_mode(G3D_MODELVIEW);
92 g3d_translate(0, 0, -cam_dist);
93 g3d_rotate(cam_phi, 1, 0, 0);
94 g3d_rotate(cam_theta, 0, 1, 0);
96 g3d_mult_matrix(sball_matrix);
99 memset(fb_pixels, 0, fb_width * fb_height * 2);
101 g3d_polygon_mode(G3D_TEX);
104 g3d_scale(-6, -6, -6);
105 g3d_set_texture(tex_outer.width, tex_outer.height, tex_outer.pixels);
106 draw_mesh(&mesh_cube);
109 g3d_set_texture(tex_inner.width, tex_inner.height, tex_inner.pixels);
110 draw_mesh(&mesh_cube);
112 swap_buffers(fb_pixels);