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 static int shading = G3D_TEX_GOURAUD;
37 static int do_clip = 1;
40 struct screen *rtxonoff_screen(void)
49 for(i=0; i<sizeof car_fname / sizeof car_fname[0]; i++) {
51 if(!(tex_car[i].pixels = img_load_pixels(cartex_fname[i],
52 &tex_car[i].width, &tex_car[i].height, IMG_FMT_RGB24))) {
53 fprintf(stderr, "failed to load car texture: %s\n", cartex_fname[i]);
56 convimg_rgb24_rgb16(tex_car[i].pixels, (unsigned char*)tex_car[i].pixels,
57 tex_car[i].width, tex_car[i].height);
60 if(load_mesh(&mesh_car[i], car_fname[i]) == -1) {
68 static void destroy(void)
73 free(mesh_car[i].varr);
74 free(mesh_car[i].iarr);
78 static void start(long trans_time)
80 g3d_matrix_mode(G3D_PROJECTION);
82 g3d_perspective(60.0, 1.3333333, 0.5, 100.0);
84 g3d_enable(G3D_CULL_FACE);
85 g3d_enable(G3D_LIGHTING);
86 g3d_enable(G3D_LIGHT0);
88 g3d_polygon_mode(shading);
91 static void update(void)
93 mouse_orbit_update(&cam_theta, &cam_phi, &cam_dist);
96 static void draw(void)
100 float t = (float)time_msec / 16.0f;
104 memset(fb_pixels, 0, fb_width * fb_height * 2);
106 g3d_matrix_mode(G3D_MODELVIEW);
108 g3d_translate(0, 0, -cam_dist);
109 g3d_rotate(cam_phi, 1, 0, 0);
110 g3d_rotate(cam_theta, 0, 1, 0);
112 g3d_set_texture(tex_car[0].width, tex_car[0].height, tex_car[0].pixels);
113 zsort_mesh(&mesh_car[0]);
115 g3d_light_color(0, 0.3, 0.3, 0.3);
118 g3d_front_face(G3D_CW);
119 draw_mesh(&mesh_car[0]);
120 g3d_front_face(G3D_CCW);
123 g3d_light_color(0, 1, 1, 1);
124 draw_mesh(&mesh_car[0]);
126 swap_buffers(fb_pixels);
129 static void keypress(int key)
131 static int lighting = 1;
132 static int clipping = 1;
136 shading = (shading + 1) % 5;
137 g3d_polygon_mode(shading);
141 lighting = !lighting;
143 g3d_enable(G3D_LIGHTING);
145 g3d_disable(G3D_LIGHTING);
150 clipping = !clipping;
152 g3d_enable(G3D_CLIP_FRUSTUM);
154 g3d_disable(G3D_CLIP_FRUSTUM);