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 int demo_init(int argc, char **argv)
38 if(load_config("demo.cfg") == -1) {
41 if((env = getenv("START_SCR"))) {
44 if(parse_args(argc, argv) == -1) {
51 if(g3d_init() == -1) {
54 g3d_framebuffer(fb_width, fb_height, fb_pixels);
57 if(music_open("data/test.mod") == -1) {
62 if(scr_init() == -1) {
66 scr = scr_lookup(opt.start_scr);
71 if(!scr || scr_change(scr, 4000) == -1) {
72 fprintf(stderr, "screen %s not found\n", opt.start_scr ? opt.start_scr : "0");
76 /* clear the framebuffer at least once */
77 memset(fb_pixels, 0, fb_width * fb_height * fb_bpp / CHAR_BIT);
85 void demo_cleanup(void)
94 float fps = (float)nframes / ((float)time_msec / 1000.0f);
95 printf("average framerate: %.1f\n", fps);
110 /* called by swap_buffers just before the actual swap */
111 void demo_post_draw(void *pixels)
115 if(dbg_curscr_name) {
116 cs_dputs(pixels, dbg_curscr_name_pos, 240 - 16, dbg_curscr_name);
124 draw_mouse_pointer(pixels);
127 #define DEST(x, y) dest[(y) * FB_WIDTH + (x)]
128 void draw_mouse_pointer(uint16_t *fb)
130 uint16_t *dest = fb + mouse_y * FB_WIDTH + mouse_x;
131 int ylines = FB_HEIGHT - mouse_y;
182 void cs_puts_font(cs_font_func csfont, int sz, void *fb, int x, int y, const char *str)
187 if(c > ' ' && c < 128) {
188 csfont(fb, x, y, c - ' ');
194 void change_screen(int idx)
196 printf("change screen %d\n", idx);
197 scr_change(scr_screen(idx), 4000);
200 void demo_keyboard(int key, int press)
220 con_active = !con_active;
231 con_active = con_input('/');
237 con_active = con_input(key);
241 if(key >= '1' && key <= '9' && key <= '1' + scr_num_screens()) {
242 change_screen(key - '1');
244 } else if(key == '0' && scr_num_screens() >= 10) {
255 void mouse_orbit_update(float *theta, float *phi, float *dist)
257 static int prev_mx, prev_my;
258 static unsigned int prev_bmask;
261 if((mouse_bmask ^ prev_bmask) == 0) {
262 int dx = mouse_x - prev_mx;
263 int dy = mouse_y - prev_my;
266 if(mouse_bmask & MOUSE_BN_LEFT) {
275 if(mouse_bmask & MOUSE_BN_RIGHT) {
278 if(*dist < 0) *dist = 0;
286 prev_bmask = mouse_bmask;