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_crate;
30 static struct g3d_mesh mesh_cube;
32 struct screen *infcubes_screen(void)
44 if(!(tex_crate.pixels = img_load_pixels("data/crate.jpg", &tex_crate.width,
45 &tex_crate.height, IMG_FMT_RGB24))) {
46 fprintf(stderr, "infcubes: failed to load crate texture\n");
50 npixels = tex_crate.width * tex_crate.height;
51 src = (unsigned char*)tex_crate.pixels;
52 dst = tex_crate.pixels;
53 for(i=0; i<npixels; i++) {
57 *dst++ = PACK_RGB16(r, g, b);
60 if(gen_cube_mesh(&mesh_cube, 1.0f, 3) == -1) {
66 static void destroy(void)
68 img_free_pixels(tex_crate.pixels);
71 static void start(long trans_time)
73 g3d_matrix_mode(G3D_PROJECTION);
75 g3d_perspective(50.0, 1.3333333, 0.5, 100.0);
77 g3d_enable(G3D_CULL_FACE);
78 g3d_disable(G3D_LIGHTING);
79 g3d_enable(G3D_LIGHT0);
81 g3d_set_texture(tex_crate.width, tex_crate.height, tex_crate.pixels);
84 static void update(void)
86 mouse_orbit_update(&cam_theta, &cam_phi, &cam_dist);
89 static void draw(void)
93 g3d_matrix_mode(G3D_MODELVIEW);
95 g3d_translate(0, 0, -cam_dist);
96 g3d_rotate(cam_phi, 1, 0, 0);
97 g3d_rotate(cam_theta, 0, 1, 0);
99 g3d_mult_matrix(sball_matrix);
102 memset(fb_pixels, 0, fb_width * fb_height * 2);
104 g3d_polygon_mode(G3D_FLAT);
107 g3d_polygon_mode(G3D_TEX);
109 draw_mesh(&mesh_cube);
111 swap_buffers(fb_pixels);
114 static void draw_cube(float sz)
116 float hsz = sz * 0.5f;
117 g3d_begin(G3D_QUADS);
118 g3d_color3b(255, 0, 0);
120 g3d_texcoord(0, 0); g3d_vertex(-hsz, -hsz, hsz);
121 g3d_texcoord(1, 0); g3d_vertex(hsz, -hsz, hsz);
122 g3d_texcoord(1, 1); g3d_vertex(hsz, hsz, hsz);
123 g3d_texcoord(0, 1); g3d_vertex(-hsz, hsz, hsz);
124 g3d_color3b(0, 255, 0);
126 g3d_texcoord(0, 0); g3d_vertex(hsz, -hsz, hsz);
127 g3d_texcoord(1, 0); g3d_vertex(hsz, -hsz, -hsz);
128 g3d_texcoord(1, 1); g3d_vertex(hsz, hsz, -hsz);
129 g3d_texcoord(0, 1); g3d_vertex(hsz, hsz, hsz);
130 g3d_color3b(0, 0, 255);
131 g3d_normal(0, 0, -1);
132 g3d_texcoord(0, 0); g3d_vertex(hsz, -hsz, -hsz);
133 g3d_texcoord(1, 0); g3d_vertex(-hsz, -hsz, -hsz);
134 g3d_texcoord(1, 1); g3d_vertex(-hsz, hsz, -hsz);
135 g3d_texcoord(0, 1); g3d_vertex(hsz, hsz, -hsz);
136 g3d_color3b(255, 0, 255);
137 g3d_normal(-1, 0, 0);
138 g3d_texcoord(0, 0); g3d_vertex(-hsz, -hsz, -hsz);
139 g3d_texcoord(1, 0); g3d_vertex(-hsz, -hsz, hsz);
140 g3d_texcoord(1, 1); g3d_vertex(-hsz, hsz, hsz);
141 g3d_texcoord(0, 1); g3d_vertex(-hsz, hsz, -hsz);
142 g3d_color3b(255, 255, 0);
144 g3d_texcoord(0, 0); g3d_vertex(-hsz, hsz, hsz);
145 g3d_texcoord(1, 0); g3d_vertex(hsz, hsz, hsz);
146 g3d_texcoord(1, 1); g3d_vertex(hsz, hsz, -hsz);
147 g3d_texcoord(0, 1); g3d_vertex(-hsz, hsz, -hsz);
148 g3d_color3b(0, 255, 255);
149 g3d_normal(0, -1, 0);
150 g3d_texcoord(0, 0); g3d_vertex(hsz, -hsz, hsz);
151 g3d_texcoord(1, 0); g3d_vertex(-hsz, -hsz, hsz);
152 g3d_texcoord(1, 1); g3d_vertex(-hsz, -hsz, -hsz);
153 g3d_texcoord(0, 1); g3d_vertex(hsz, -hsz, -hsz);