13 static int init(void);
14 static void destroy(void);
15 static void start(long trans_time);
16 static void draw(void);
18 static struct screen scr = {
26 static float cam_theta = -29, cam_phi = 35;
27 static float cam_dist = 6;
29 static const char *car_fname[2] = {"data/ldiablo.obj", 0};
30 static const char *cartex_fname[2] = {"data/ldiablo.png", 0};
31 static struct g3d_mesh mesh_car[2];
32 static struct pimage tex_car[2];
34 struct screen *rtxonoff_screen(void)
43 for(i=0; i<sizeof car_fname / sizeof car_fname[0]; i++) {
45 if(!(tex_car[i].pixels = img_load_pixels(cartex_fname[i],
46 &tex_car[i].width, &tex_car[i].height, IMG_FMT_RGB24))) {
47 fprintf(stderr, "failed to load car texture: %s\n", cartex_fname[i]);
49 convimg_rgb24_rgb16(tex_car[i].pixels, (unsigned char*)tex_car[i].pixels,
50 tex_car[i].width, tex_car[i].height);
53 if(load_mesh(&mesh_car[i], car_fname[i]) == -1) {
61 static void destroy(void)
65 static void start(long trans_time)
67 g3d_matrix_mode(G3D_PROJECTION);
69 g3d_perspective(60.0, 1.3333333, 0.5, 100.0);
71 g3d_enable(G3D_CULL_FACE);
72 g3d_enable(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)
84 float t = (float)time_msec / 16.0f;
88 memset(fb_pixels, 0, fb_width * fb_height * 2);
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_polygon_mode(G3D_TEX_GOURAUD);
98 for(i=0; i<sizeof mesh_car / sizeof mesh_car[0]; i++) {
99 if(mesh_car[i].varr) {
100 g3d_set_texture(tex_car[i].width, tex_car[i].height, tex_car[i].pixels);
102 zsort_mesh(&mesh_car[i]);
103 draw_mesh(&mesh_car[i]);
107 swap_buffers(fb_pixels);