12 static int init(void);
13 static void destroy(void);
14 static void start(long trans_time);
15 static void draw(void);
16 static void draw_cube(float sz);
18 static struct screen scr = {
26 static float cam_theta = -29, cam_phi = 35;
27 static float cam_dist = 5;
28 static struct pimage tex_crate;
30 struct screen *infcubes_screen(void)
42 if(!(tex_crate.pixels = img_load_pixels("data/crate.jpg", &tex_crate.width,
43 &tex_crate.height, IMG_FMT_RGB24))) {
44 fprintf(stderr, "infcubes: failed to load crate texture\n");
48 npixels = tex_crate.width * tex_crate.height;
49 src = (unsigned char*)tex_crate.pixels;
50 dst = tex_crate.pixels;
51 for(i=0; i<npixels; i++) {
55 *dst++ = PACK_RGB16(r, g, b);
60 static void destroy(void)
62 img_free_pixels(tex_crate.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);
75 g3d_set_texture(tex_crate.width, tex_crate.height, tex_crate.pixels);
78 static void update(void)
80 mouse_orbit_update(&cam_theta, &cam_phi, &cam_dist);
83 static void draw(void)
87 g3d_matrix_mode(G3D_MODELVIEW);
89 g3d_translate(0, 0, -cam_dist);
90 g3d_rotate(cam_phi, 1, 0, 0);
91 g3d_rotate(cam_theta, 0, 1, 0);
93 g3d_mult_matrix(sball_matrix);
96 memset(fb_pixels, 0, fb_width * fb_height * 2);
98 g3d_polygon_mode(G3D_FLAT);
101 g3d_polygon_mode(G3D_TEX);
104 swap_buffers(fb_pixels);
107 static void draw_cube(float sz)
109 float hsz = sz * 0.5f;
110 g3d_begin(G3D_QUADS);
111 g3d_color3b(255, 0, 0);
113 g3d_texcoord(0, 0); g3d_vertex(-hsz, -hsz, hsz);
114 g3d_texcoord(1, 0); g3d_vertex(hsz, -hsz, hsz);
115 g3d_texcoord(1, 1); g3d_vertex(hsz, hsz, hsz);
116 g3d_texcoord(0, 1); g3d_vertex(-hsz, hsz, hsz);
117 g3d_color3b(0, 255, 0);
119 g3d_texcoord(0, 0); g3d_vertex(hsz, -hsz, hsz);
120 g3d_texcoord(1, 0); g3d_vertex(hsz, -hsz, -hsz);
121 g3d_texcoord(1, 1); g3d_vertex(hsz, hsz, -hsz);
122 g3d_texcoord(0, 1); g3d_vertex(hsz, hsz, hsz);
123 g3d_color3b(0, 0, 255);
124 g3d_normal(0, 0, -1);
125 g3d_texcoord(0, 0); g3d_vertex(hsz, -hsz, -hsz);
126 g3d_texcoord(1, 0); g3d_vertex(-hsz, -hsz, -hsz);
127 g3d_texcoord(1, 1); g3d_vertex(-hsz, hsz, -hsz);
128 g3d_texcoord(0, 1); g3d_vertex(hsz, hsz, -hsz);
129 g3d_color3b(255, 0, 255);
130 g3d_normal(-1, 0, 0);
131 g3d_texcoord(0, 0); g3d_vertex(-hsz, -hsz, -hsz);
132 g3d_texcoord(1, 0); g3d_vertex(-hsz, -hsz, hsz);
133 g3d_texcoord(1, 1); g3d_vertex(-hsz, hsz, hsz);
134 g3d_texcoord(0, 1); g3d_vertex(-hsz, hsz, -hsz);
135 g3d_color3b(255, 255, 0);
137 g3d_texcoord(0, 0); g3d_vertex(-hsz, hsz, hsz);
138 g3d_texcoord(1, 0); g3d_vertex(hsz, hsz, hsz);
139 g3d_texcoord(1, 1); g3d_vertex(hsz, hsz, -hsz);
140 g3d_texcoord(0, 1); g3d_vertex(-hsz, hsz, -hsz);
141 g3d_color3b(0, 255, 255);
142 g3d_normal(0, -1, 0);
143 g3d_texcoord(0, 0); g3d_vertex(hsz, -hsz, hsz);
144 g3d_texcoord(1, 0); g3d_vertex(-hsz, -hsz, hsz);
145 g3d_texcoord(1, 1); g3d_vertex(-hsz, -hsz, -hsz);
146 g3d_texcoord(0, 1); g3d_vertex(hsz, -hsz, -hsz);