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 keypress(int key);
19 static struct screen scr = {
28 static float cam_theta = -29, cam_phi = 35;
29 static float cam_dist = 10;
31 static const char *car_fname[2] = {"data/ldiablo.obj", 0};
32 static const char *cartex_fname[2] = {"data/ldiablo.png", 0};
33 static struct g3d_mesh mesh_car[2];
34 static struct pimage tex_car[2];
36 struct screen *rtxonoff_screen(void)
45 for(i=0; i<sizeof car_fname / sizeof car_fname[0]; i++) {
47 if(!(tex_car[i].pixels = img_load_pixels(cartex_fname[i],
48 &tex_car[i].width, &tex_car[i].height, IMG_FMT_RGB24))) {
49 fprintf(stderr, "failed to load car texture: %s\n", cartex_fname[i]);
52 convimg_rgb24_rgb16(tex_car[i].pixels, (unsigned char*)tex_car[i].pixels,
53 tex_car[i].width, tex_car[i].height);
56 if(load_mesh(&mesh_car[i], car_fname[i]) == -1) {
64 static void destroy(void)
69 free(mesh_car[i].varr);
70 free(mesh_car[i].iarr);
74 static void start(long trans_time)
76 g3d_matrix_mode(G3D_PROJECTION);
78 g3d_perspective(60.0, 1.3333333, 0.5, 100.0);
80 g3d_enable(G3D_CULL_FACE);
81 g3d_enable(G3D_LIGHTING);
82 g3d_enable(G3D_LIGHT0);
85 static void update(void)
87 mouse_orbit_update(&cam_theta, &cam_phi, &cam_dist);
90 static void draw(void)
94 float t = (float)time_msec / 16.0f;
98 memset(fb_pixels, 0, fb_width * fb_height * 2);
100 g3d_matrix_mode(G3D_MODELVIEW);
102 g3d_translate(0, 0, -cam_dist);
103 g3d_rotate(cam_phi, 1, 0, 0);
104 g3d_rotate(cam_theta, 0, 1, 0);
106 g3d_polygon_mode(G3D_TEX_GOURAUD);
108 for(i=0; i<sizeof mesh_car / sizeof mesh_car[0]; i++) {
109 if(mesh_car[i].varr) {
110 g3d_set_texture(tex_car[i].width, tex_car[i].height, tex_car[i].pixels);
112 zsort_mesh(&mesh_car[i]);
113 draw_mesh(&mesh_car[i]);
117 swap_buffers(fb_pixels);
120 static void keypress(int key)