20 int fb_width = FB_WIDTH;
21 int fb_height = FB_HEIGHT;
23 uint16_t *fb_pixels, *vmem;
24 unsigned long time_msec;
26 unsigned int mouse_bmask;
28 float sball_matrix[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
30 static unsigned long nframes;
31 static int con_active;
33 extern uint16_t loading_pixels[]; /* data.asm */
36 int demo_init(int argc, char **argv)
41 if(load_config("demo.cfg") == -1) {
44 if((env = getenv("START_SCR"))) {
47 if(parse_args(argc, argv) == -1) {
51 /* reuse the loading image as our back buffer.
52 * adjust fb_pixels to leave 4 pixels guard band top/bottom. We have enough
53 * space since the loading image is 8 pixels taller.
55 fb_pixels = loading_pixels + 320 * 4;
60 if(g3d_init() == -1) {
63 g3d_framebuffer(fb_width, fb_height, fb_pixels);
66 if(music_open("data/test.mod") == -1) {
71 if(scr_init() == -1) {
75 scr = scr_lookup(opt.start_scr);
80 if(!scr || scr_change(scr, 4000) == -1) {
81 fprintf(stderr, "screen %s not found\n", opt.start_scr ? opt.start_scr : "0");
85 /* clear the framebuffer at least once */
86 memset(fb_pixels, 0, fb_width * fb_height * fb_bpp / CHAR_BIT);
94 void demo_cleanup(void)
103 float fps = (float)nframes / ((float)time_msec / 1000.0f);
104 printf("average framerate: %.1f\n", fps);
119 /* called by swap_buffers just before the actual swap */
120 void demo_post_draw(void *pixels)
124 if(dbg_curscr_name) {
125 cs_dputs(pixels, dbg_curscr_name_pos, 240 - 16, dbg_curscr_name);
133 draw_mouse_pointer(pixels);
136 #define DEST(x, y) dest[(y) * FB_WIDTH + (x)]
137 void draw_mouse_pointer(uint16_t *fb)
139 uint16_t *dest = fb + mouse_y * FB_WIDTH + mouse_x;
140 int ylines = FB_HEIGHT - mouse_y;
191 void cs_puts_font(cs_font_func csfont, int sz, void *fb, int x, int y, const char *str)
196 if(c > ' ' && c < 128) {
197 csfont(fb, x, y, c - ' ');
203 void change_screen(int idx)
205 printf("change screen %d\n", idx);
206 scr_change(scr_screen(idx), 4000);
209 void demo_keyboard(int key, int press)
229 con_active = !con_active;
240 con_active = con_input('/');
246 con_active = con_input(key);
250 if(key >= '1' && key <= '9' && key <= '1' + scr_num_screens()) {
251 change_screen(key - '1');
253 } else if(key == '0' && scr_num_screens() >= 10) {
264 void mouse_orbit_update(float *theta, float *phi, float *dist)
266 static int prev_mx, prev_my;
267 static unsigned int prev_bmask;
270 if((mouse_bmask ^ prev_bmask) == 0) {
271 int dx = mouse_x - prev_mx;
272 int dy = mouse_y - prev_my;
275 if(mouse_bmask & MOUSE_BN_LEFT) {
284 if(mouse_bmask & MOUSE_BN_RIGHT) {
287 if(*dist < 0) *dist = 0;
295 prev_bmask = mouse_bmask;