int main(int argc, char *argv[]) { int i,j,k; char c; int res=0; int x,y; char buttons; struct termios t_new,t_old; FILE *fsc; char buf[100]; progname=argv[0]; screen_gamma=1.5; #ifdef DEBUG log=fopen("/png/view.log","w"); #endif while((c=getopt(argc,argv,"r:g:"))!=-1) { switch(c) { case 'r': res=atoi(optarg); if(res>0) max_screen_colors=256; break; case 'g': screen_gamma=atof(optarg); break; case '?': default: usage(); exit(0); } } switch(res) { case 0: VGLInit(SW_CG640x480); break; case 1: VGLInit(SW_VGA_CG320); break; case 2: VGLInit(SW_VGA_MODEX); break; default: fprintf(stderr,"No such resolution!\n"); usage(); exit(-1); } #ifdef DEBUG fprintf(log,"VGL initialised\n"); #endif VGLSavePalette(); if(argc>optind) { res=png_load(argv[optind]); } else { VGLEnd(); usage(); exit(0); } if(res) { /* Hmm... Script? */ fsc=fopen(argv[optind],"r"); #ifdef DEBUG fprintf(log,"Trying script %s\n",argv[optind]); #endif fgets(buf,99,fsc); buf[strlen(buf)-1]='\0'; if(strncmp("VIEW SCRIPT",buf,11)!=NULL) { VGLEnd(); usage(); } if(strlen(buf)>12) { auto_chg=atoi(buf+12); } fgets(buf,99,fsc); buf[strlen(buf)-1]='\0'; nimg=atoi(buf); if(nimg==0) { VGLEnd(); usage(); } pres=(char **)calloc(nimg,sizeof(char *)); for(i=0;i<nimg;i++) { fgets(buf,99,fsc); buf[strlen(buf)-1]='\0'; pres[i]=strdup(buf); } fclose(fsc); cur_img=0; #ifdef DEBUG fprintf(log,"Script with %d entries\n",nimg); #endif png_load(pres[cur_img]); } VGLMouseInit(VGL_MOUSEHIDE); /* Prepare the keyboard */ tcgetattr(0,&t_old); memcpy(&t_new,&t_old,sizeof(struct termios)); cfmakeraw(&t_new); tcsetattr(0,TCSAFLUSH,&t_new); fcntl(0,F_SETFL,O_ASYNC); /* XXX VGLClear doesn't work.. :-(( Prepare a blank background */ bkg.Bitmap=(byte *)calloc(VGLDisplay->Xsize*VGLDisplay->Ysize,1); bkg.Xsize=VGLDisplay->Xsize; bkg.Ysize=VGLDisplay->Ysize; bkg.Type=VGLDisplay->Type; signal(SIGIO,kbd_handler); a.zoom=1; a.Xshift=(VGLDisplay->Xsize-pic.Xsize)/2; a.Yshift=(VGLDisplay->Ysize-pic.Ysize)/2; a.rotate=0; quit=0; changed=0; display(&pic,pal_red,pal_green,pal_blue,&a); while(!quit) { if(act) { #ifdef DEBUG fprintf(log,"kbd_action(%c)\n",act); #endif kbd_action(x,y,act); } if(quit) break; if(changed) { #ifdef DEBUG fprintf(log,"changed, redisplaying\n"); #endif display(&pic,pal_red,pal_green,pal_blue,&a); changed=0; } if(auto_chg) { sleep(auto_chg); kbd_action(x,y,'n'); } else { pause(); } VGLMouseStatus(&x,&y,&buttons); if(buttons & MOUSE_BUTTON3DOWN) { #ifdef DEBUG fprintf(log,"pop_up called\n"); #endif pop_up("View",x,y); } } VGLEnd(); #ifdef DEBUG fclose(log); #endif exit(0); }
int main(int argc, char **argv) { int y, xsize, ysize, i,j; VGLBitmap *tmp; // set graphics mode, here 320x240 256 colors // supported modes are (from <sys/consio.h>): // SW_VGA_CG320: std VGA 320x200 256 colors // SW_VGA_MODEX: Modex VGA 320x240 256 colors // SW_VGA_VG640: std VGA 640x480 16 colors VGLInit(SW_VGA_MODEX); // initialize mouse and show pointer VGLMouseInit(VGL_MOUSESHOW); // VGLDisplay is a ptr to a struct Bitmap defined and initialized by // libvgl. The Bitmap points directly to screen memory etc. xsize=VGLDisplay->Xsize; ysize=VGLDisplay->Ysize; // alloc a new bitmap tmp = VGLBitmapCreate(MEMBUF, 256, 256, NULL); VGLBitmapAllocateBits(tmp); VGLClear(tmp, 0); // fill the screen with colored lines for (y=0; y<ysize; y++) VGLLine(VGLDisplay, 0, y, xsize-1, y, y/2 % 256); // draw some lines and circles just to show off VGLLine(VGLDisplay, 0, 0, xsize-1, ysize-1, 63); VGLLine(VGLDisplay, 0, ysize-1, xsize-1, 0, 63); VGLLine(VGLDisplay, 0, 0, 0, ysize-1, 63); VGLLine(VGLDisplay, xsize-1, 0, xsize-1, ysize-1, 63); VGLEllipse(VGLDisplay, 256, 0, 256, 256, 63); VGLEllipse(VGLDisplay, 0, 256, 256, 256, 0); // some text is also useful VGLBitmapString(VGLDisplay, 100,100, "This is text", 63, 0, 0, VGL_DIR_RIGHT); sleep(2); VGLBitmapString(VGLDisplay, 100,100, "This is text", 63, 0, 0, VGL_DIR_UP); sleep(2); VGLBitmapString(VGLDisplay, 100,100, "This is text", 63, 0, 0, VGL_DIR_LEFT); sleep(2); VGLBitmapString(VGLDisplay, 100,100, "This is text", 63, 0, 0, VGL_DIR_DOWN); sleep(2); // now show some simple bitblit for (i=0; i<256; i++) for (j=0; j<256; j++) tmp->Bitmap[i+256*j] = i%16; VGLBitmapCopy(tmp, 0, 0, VGLDisplay, 0, 0, 128, 128); for (i=0; i<256; i++) for (j=0; j<256; j++) tmp->Bitmap[i+256*j] = j%16; VGLBitmapCopy(tmp, 0, 0, VGLDisplay, 3, 128, 128, 128); sleep(2); VGLBitmapCopy(VGLDisplay, 237, 311, tmp, 64, 64, 128, 128); VGLBitmapCopy(tmp, 32, 32, VGLDisplay, 400, 128, 128, 128); sleep(2); VGLBitmapCopy(VGLDisplay, 300, 300, VGLDisplay, 500, 128, 128, 128); sleep(5); i=0; // loop around drawing and copying while (++i) { VGLBitmapCopy(VGLDisplay, rand()%xsize, rand()%ysize, VGLDisplay, rand()%xsize, rand()%ysize, rand()%xsize, rand()%ysize); VGLLine(VGLDisplay, rand()%xsize, rand()%ysize, rand()%xsize, rand()%ysize, rand()%256); VGLEllipse(VGLDisplay, rand()%xsize, rand()%ysize, rand()%xsize/2, rand()%ysize/2, rand()%256); rand(); if (i > 1000) break; } // restore screen to its original mode VGLEnd(); return 0; }