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);
54 if(gen_cube_mesh(&mesh_cube, 1.0f, 3) == -1) {
60 static void destroy(void)
62 img_free_pixels(tex_inner.pixels);
65 static void start(long trans_time)
67 g3d_matrix_mode(G3D_PROJECTION);
69 g3d_perspective(50.0, 1.3333333, 0.5, 100.0);
71 g3d_enable(G3D_CULL_FACE);
72 g3d_disable(G3D_LIGHTING);
73 g3d_enable(G3D_LIGHT0);
76 static void update(void)
78 mouse_orbit_update(&cam_theta, &cam_phi, &cam_dist);
81 static void draw(void)
85 g3d_matrix_mode(G3D_MODELVIEW);
87 g3d_translate(0, 0, -cam_dist);
88 g3d_rotate(cam_phi, 1, 0, 0);
89 g3d_rotate(cam_theta, 0, 1, 0);
91 g3d_mult_matrix(sball_matrix);
94 memset(fb_pixels, 0, fb_width * fb_height * 2);
96 g3d_polygon_mode(G3D_TEX);
99 g3d_scale(-6, -6, -6);
100 g3d_set_texture(tex_outer.width, tex_outer.height, tex_outer.pixels);
101 draw_mesh(&mesh_cube);
104 g3d_set_texture(tex_inner.width, tex_inner.height, tex_inner.pixels);
105 draw_mesh(&mesh_cube);
107 swap_buffers(fb_pixels);
110 static void draw_cube(float sz)
112 float hsz = sz * 0.5f;
113 g3d_begin(G3D_QUADS);
114 g3d_color3b(255, 0, 0);
116 g3d_texcoord(0, 0); g3d_vertex(-hsz, -hsz, hsz);
117 g3d_texcoord(1, 0); g3d_vertex(hsz, -hsz, hsz);
118 g3d_texcoord(1, 1); g3d_vertex(hsz, hsz, hsz);
119 g3d_texcoord(0, 1); g3d_vertex(-hsz, hsz, hsz);
120 g3d_color3b(0, 255, 0);
122 g3d_texcoord(0, 0); g3d_vertex(hsz, -hsz, hsz);
123 g3d_texcoord(1, 0); g3d_vertex(hsz, -hsz, -hsz);
124 g3d_texcoord(1, 1); g3d_vertex(hsz, hsz, -hsz);
125 g3d_texcoord(0, 1); g3d_vertex(hsz, hsz, hsz);
126 g3d_color3b(0, 0, 255);
127 g3d_normal(0, 0, -1);
128 g3d_texcoord(0, 0); g3d_vertex(hsz, -hsz, -hsz);
129 g3d_texcoord(1, 0); g3d_vertex(-hsz, -hsz, -hsz);
130 g3d_texcoord(1, 1); g3d_vertex(-hsz, hsz, -hsz);
131 g3d_texcoord(0, 1); g3d_vertex(hsz, hsz, -hsz);
132 g3d_color3b(255, 0, 255);
133 g3d_normal(-1, 0, 0);
134 g3d_texcoord(0, 0); g3d_vertex(-hsz, -hsz, -hsz);
135 g3d_texcoord(1, 0); g3d_vertex(-hsz, -hsz, hsz);
136 g3d_texcoord(1, 1); g3d_vertex(-hsz, hsz, hsz);
137 g3d_texcoord(0, 1); g3d_vertex(-hsz, hsz, -hsz);
138 g3d_color3b(255, 255, 0);
140 g3d_texcoord(0, 0); g3d_vertex(-hsz, hsz, hsz);
141 g3d_texcoord(1, 0); g3d_vertex(hsz, hsz, hsz);
142 g3d_texcoord(1, 1); g3d_vertex(hsz, hsz, -hsz);
143 g3d_texcoord(0, 1); g3d_vertex(-hsz, hsz, -hsz);
144 g3d_color3b(0, 255, 255);
145 g3d_normal(0, -1, 0);
146 g3d_texcoord(0, 0); g3d_vertex(hsz, -hsz, hsz);
147 g3d_texcoord(1, 0); g3d_vertex(-hsz, -hsz, hsz);
148 g3d_texcoord(1, 1); g3d_vertex(-hsz, -hsz, -hsz);
149 g3d_texcoord(0, 1); g3d_vertex(hsz, -hsz, -hsz);